タブ区切り記号

タブ区切り記号

私はこれが簡単だと思いますが、それを行う方法がわかりません。

想像する

、、、列を.csv含むファイルがあり、各列は次のように区切ります。id_usertextid_grouptabs

"123456789"        "Here's the field of the text, also contains comma"        "10"
"987456321"        "Here's the field of the text, also contains comma"        "10"
"123654789"        "Here's the field of the text, also contains comma"        "11"
"987456123"        "Here's the field of the text, also contains comma"        "11"

テキストを見つける方法は?

試みる

アッ

区切り文字を指定する方法を探していますprint $n。そうすることができれば、1つのオプションは次のとおりです。

$ awk -d '\t' '{print $2}' file.csv | sed -e 's/"//gp'

-dオプションの区切り文字はどこにあり、削除されますprintsed"

ベストアンサー1

タブ区切り記号

切る

sedorは不要で、awk簡単な方法でcut行われます。

cut -f2 infile

アッ

awkを使用するには、パラメータまたはサフィックスを介して区切り-F文字FS=を提供する方法があります。

awk -F '\t' '{ print $2 }' infile

または:

awk '{ print $2 }' FS='\t' infile

すべての場合の出力:

"Here's the field of the text, also contains comma"
"Here's the field of the text, also contains comma"
"Here's the field of the text, also contains comma"
"Here's the field of the text, also contains comma"

引用区切り記号

ファイルに二重引用符が一貫している場合、つまりフィールドに二重引用符が含まれていない場合は、区切り文字として使用し、出力では使用しないことがあります。たとえば、次のようになります。

切る

cut -d\" -f4 infile

アッ

awk -F\" '{ print $4 }' infile

どちらの場合も出力:

Here's the field of the text, also contains comma
Here's the field of the text, also contains comma
Here's the field of the text, also contains comma
Here's the field of the text, also contains comma

おすすめ記事