Print Lines having unique fields
I have a table in which most of the values in a given row are the same. What I want to pull out are any rows where at least one of the values is different.For example I have a file:
one one one one two two two two two two three four four fiveI found a nice trick for doing this:
awk '{f=$0;gsub($1,"")}NF{print f}' file
one one one one two
three four four five
First we store the line in original state f=$0 then we do a global substitution on everything matching the first field, if all fields are the same then nothing will be left therefor NF will be 0 and nothing will be printed else we print the original line.
.png)







I am a software programmer working in India. I usually like to blog in my free time.
0 comments: