Reputation: 67
I have a number of files I want to process. For each one, I want to remove any rows where the value in the 6th column is less than 50. I tried using: awk '($6 >= 50)'. However, this removes the header lines from the files, which I want to keep.
Each line of the header starts with a '#' symbol. So I need to modify the command so that it doesn't remove any lines that start with a #.
Upvotes: 0
Views: 262
Reputation: 72649
This sounds like the first pattern/action statement in your script should be
/^#/ { print; next }
The next
statement causes awk to skip the remaining pattern/action combos and continue with the next line.
Upvotes: 0
Reputation: 289725
Just say
awk '$1 ~ /^#/ || ($6>=50)' file
This tells awk
to print lines that match either of these:
#
. This way, leading spaces are overlooked, orLittle test:
$ cat a
a1 2 3 4 5 52
a2 2 3 4 5 52
#a3 2 3 4 5 12
#a4 2 3 4 5 12
a5 2 3 4 5 12
$ awk '$1 ~ /^#/ || ($6>=50)' a
a1 2 3 4 5 52
a2 2 3 4 5 52
#a3 2 3 4 5 12
#a4 2 3 4 5 12
Upvotes: 2