awk取出特定字段_在Linux上如何使用awk在特定字段之后打印所有字段?

awk取出特定字段

How to print all fields after a certain field with awk on Linux?

如何在Linux上使用awk 打印特定字段之后的所有字段?

Say, I want to print out all fields after field $3:

说,我要打印出字段$3之后的所有字段:

a b c d e f
a b b b
a a c d

should be transformed to

应该转化为

d e f
b
d

You may use a for loop in awk to print fields from $4 to $NF with a space as the separator:

您可以在awk中使用for循环来打印从$4$NF字段,并以空格作为分隔符:

awk '{for (i=4; i= 4) print $NF; }' in.txt

printf print the field and a following space. The if statement makes sure nothing is printed out if the number of fields is less than 4. The last print statement prints the last field without the additional space yet with a newline.

printf打印字段和后续空格。 if字段数少于4, if语句可确保不打印任何内容。last print语句将打印最后一个字段,且不带附加空间,但带有换行符。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/how-to-print-all-fields-after-a-certain-field-with-awk-on-linux/

awk取出特定字段

你可能感兴趣的:(awk,linux,sql,wordpress,java)