I want to remove duplicate lines from /etc/fstab
, so I did this:
awk '!NF || !seen[$0]++' /etc/fstab > /etc/fstab.update
UUID=3de0d101-fba7-4d89-b038-58fe07295d96 /grid/sdb ext4 defaults,noatime 0 0
UUID=683ed0b3-51fe-4dc4-975e-d56c0bbaf0bc /grid/sdc ext4 defaults,noatime 0 0
UUID=1cf79946-0ba6-4cd8-baca-80c0a2693de1 /grid/sdd ext4 defaults,noatime 0 0
UUID=fa9cc6e8-4df8-4330-9144-ede46b94c49e /grid/sde ext4 defaults,noatime 0 0
UUID=3de0d101-fba7-4d89-b038-58fe07295d96 /grid/sdb ext4 defaults,noatime 0 0
UUID=683ed0b3-51fe-4dc4-975e-d56c0bbaf0bc /grid/sdc ext4 defaults,noatime 0 0
But as we can see, the last two lines are the same with the first two lines, but last two lines are with spaces.
Is it possible to ignore the space and remove the duplicate lines anyway?
"hello\n\nworld"
should remain as "hello\n\nworld" but your solutions removes the empty line as well. I was just asking could we prevent the empty new line to be removed. – alper Jul 10 '21 at 19:29awk 'NF{$1=$1};!NF||!seen[$0]++' filename
. – Quasímodo Jul 12 '21 at 12:48