tac*_*omi 3 sed awk text-processing
我认为这会很简单,但不知道如何去做。
设想
我有一个.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"
Run Code Online (Sandbox Code Playgroud)
如何找到文本?
试图
awk
我正在寻找一种指定print $n分隔符的方法,如果可以的话,一个选项将是
$ awk -d '\t' '{print $2}' file.csv | sed -e 's/"//gp'
Run Code Online (Sandbox Code Playgroud)
选项-d的分隔符print和sed取出的分隔符在哪里"
Tho*_*hor 10
你不需要sedor awk,一个简单的cut就可以:
cut -f2 infile
Run Code Online (Sandbox Code Playgroud)
如果要使用 awk,提供定界符的方法是通过-F参数或作为FS=后缀:
awk -F '\t' '{ print $2 }' infile
Run Code Online (Sandbox Code Playgroud)
或者:
awk '{ print $2 }' FS='\t' infile
Run Code Online (Sandbox Code Playgroud)
cut -f2 infile
Run Code Online (Sandbox Code Playgroud)
如果文件中的双引号一致,即字段中没有嵌入双引号,则可以将它们用作分隔符并避免在输出中使用它们,例如:
cut -d\" -f4 infile
Run Code Online (Sandbox Code Playgroud)
awk -F\" '{ print $4 }' infile
Run Code Online (Sandbox Code Playgroud)
awk -F '\t' '{ print $2 }' infile
Run Code Online (Sandbox Code Playgroud)