これらの文字列を書き換えて「#」で始まる文字列部分を文字列自体の上に配置できますか?

これらの文字列を書き換えて「#」で始まる文字列部分を文字列自体の上に配置できますか?

シンプルで迅速な質問です。

私はこれを持っています

awk -f file            # awk use file as input
awk '/word/' file      # awk show me word
awk '/32$/' text       # all words with 32..

私はこれが欲しい

# awk use file as input
awk -f file       


# awk show me word                                              
awk '/word/' file      


# all words with 32..                                         
awk '/32$/' text  

awkを使ってこれを行うことはできますか?他のコマンドも歓迎します(perl、sed、python..)

ベストアンサー1

$ awk -F '[[:space:]]+#' '{print "#" $2 ORS $1 ORS}' file
# awk use file as input
awk -f file

# awk show me word
awk '/word/' file

# all words with 32..
awk '/32$/' text

#ただし、これは、入力入力/出力例のように、各入力行の1の前にスペースがある場合にのみ機能します。実際のデータがそうでない場合は、質問を編集して、#awkコードおよび/またはコメントからスペースの前にあるものを含む、より実際的な入力/出力の例を提供してください。

awk '/foo # bar/' file          # lines with # before bar

#そしてそのような場合(特にコメントのs)を処理​​するアルゴリズムを教えてください。

おすすめ記事