I have a sorted file with lines like this
word1 abca word1 abcb word1 abcc word2 abca word2 abcb word3 abbb ...........
and i want to have something like this
word1 abca word2 abca word3 abbb ...........
This magic incantation is a famous awk idiom:
The first time a line with that $1 is seen, the line is printed.
An awk solution - using a variable to detect a new word. If a new word is found, print the line and assign the variable to the current word.
As the data file is sorted, only the 1st occurence of each word will print the record.
You could also use the
Alternatively, reverse the order of the fields and use
Or get the 1st fields and then
And, for completion's sake, a Perl one: