Hello,
Would someone be able to tell me exactly how this command works please?
awk '!x[$0]++'
As usual any help much appreciated
Hello,
Would someone be able to tell me exactly how this command works please?
awk '!x[$0]++'
As usual any help much appreciated
It eliminates matching lines by printing only lines which were not previously added to an array (x)
Thanks Scott. I've been using it to remove blank lines from a file but I wondered what all the specific characters mean. IE:
!x
[$0]
++
It will not only eliminate blank lines, but also nonempty duplicate lines. To delete blank lines this would be better:
awk '!/^$/'
Hi.
It won't remove the first blank line - it only removes duplicate lines (blank or otherwise).
To remove all blank lines, the bartus11 solution is more suited.
Or
awk NF
Or
grep .
LOL
LOL
tr -s \\n
What I like about awk NF is that it will also remove non-empty lines that contain just spaces and/or tabs..
You're right. Anything that "just handles" whitespace without delimiters getting in the way is perfect for the job.

There are times when I wish all *nix commands would "just handle" whitespace. But I'm sure that would annoy me more that it wouldn't 