Results 1 to 7 of 7
I have a file that has many lines. But I want to print only unique lines in that file. i.e. I dont want to print similar lines. How to do ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-15-2006 #1Just Joined!
- Join Date
- Sep 2006
- Posts
- 4
how to print unique lines from a file?
I have a file that has many lines. But I want to print only unique lines in that file. i.e. I dont want to print similar lines. How to do it?
- 09-15-2006 #2
Use grep.
You can take each line from a file, use grep to count the matches in that same file, and if the number found is only 1, echo the line to the display.Linux user #126863 - see http://linuxcounter.net/
- 09-15-2006 #3Just Joined!
- Join Date
- Sep 2006
- Posts
- 4
help ?????
but suppose there are 5 similar lines in the file then I want to print only one of the 5 lines.? pls help
- 09-15-2006 #4
Errrr, forgive me for not understanding what you're saying, but...
If there are 5 similar lines in the file (and similar means 'nearly the same' not 'unique') then what you asked in the first place was for something that will print them all...
Perhaps you could mackle some kind of bash algorthim that checked each character in the line with each other character, and if maybe 80% match up, then you could treat them as the same? Sounds quite tricky though. 'Nearly the same' or 'approximately equal to' is quite hard to do in computer terms.Linux user #126863 - see http://linuxcounter.net/
- 09-15-2006 #5sort sorts, uniq removes similar consecutive lines. That'll work fine if you don't mind the order of the lines being changed.Code:
sort <file> | uniq
Flies of a particular kind, i.e. time-flies, are fond of an arrow.
Registered Linux User #408794
- 09-15-2006 #6
Another option is to use "sort -u" and then redirect the output to lpr or another file e.g.
orCode:#sort -u somefile | lpr
Code:#sort -u somefile >> someotherfile
- 12-10-2010 #7Just Joined!
- Join Date
- Dec 2010
- Posts
- 1
I have a qmail server that every now again gets filled up by my users, so to find out which email campaign is breaking it I run the following.
./qmHandle -R | grep Subject | sort | uniq > subjects.txt



