私はこれが簡単だと思いますが、それを行う方法がわかりません。
想像する
、、、列を.csv
含むファイルがあり、各列は次のように区切ります。id_user
text
id_group
tabs
"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
オプションの区切り文字はどこにあり、削除されますprint
。sed
"
ベストアンサー1
タブ区切り記号
切る
sed
orは不要で、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