Despite the clearly defined meaning of the .uniq command in unix, there many things that are "almost like uniq" that are too valuable to give up on. Personally, I find it hard to use uniq because I always want it to do more than it is normally actually defined to do. Basically, I make up requirements on the fly and get mad when uniq doesn't meet them.
I added some of them in brash's .uniq command.
One is activated using the -1 option which means:
Print 1 copy of all line patterns in the file -- that is filter out duplicates leaving exactly one copy of each line pattern in the file.
This is nice because it lets you get a complete list of distinct lines from the input.
Here's an example: suppose you run the grep -r -n to find all the lines in all the files matching a pattern. You get lines that look like this:
In brash, you get the distinct list of filenames using this approach:
1. use .regexp -p -r to get rid of the line number and the stuff
2. use sort to get the remaining list of file names (with duplicates) arranged for .uniq
3. use .uniq -1 on the output sort to get the right data
That data being the complete list of file names;
filename1
fiilename2
filename31
On unix, the sort -u command does something like this, I think, but the windows sort has no -u option. Using brash, you combine sort with .uniq -1 to get the feature.
Note that you can use the Windows sort command or use the .sort function defined in .brashrc.
Last edit: Lowell Boggs, Jr. 2016-07-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Despite the clearly defined meaning of the .uniq command in unix, there many things that are "almost like uniq" that are too valuable to give up on. Personally, I find it hard to use uniq because I always want it to do more than it is normally actually defined to do. Basically, I make up requirements on the fly and get mad when uniq doesn't meet them.
I added some of them in brash's .uniq command.
One is activated using the -1 option which means:
Print 1 copy of all line patterns in the file -- that is filter out duplicates leaving exactly one copy of each line pattern in the file.
This is nice because it lets you get a complete list of distinct lines from the input.
Here's an example: suppose you run the grep -r -n to find all the lines in all the files matching a pattern. You get lines that look like this:
In brash, you get the distinct list of filenames using this approach:
1. use .regexp -p -r to get rid of the line number and the stuff
2. use sort to get the remaining list of file names (with duplicates) arranged for .uniq
3. use .uniq -1 on the output sort to get the right data
That data being the complete list of file names;
filename1
fiilename2
filename31
On unix, the sort -u command does something like this, I think, but the windows sort has no -u option. Using brash, you combine sort with .uniq -1 to get the feature.
Note that you can use the Windows sort command or use the .sort function defined in .brashrc.
Last edit: Lowell Boggs, Jr. 2016-07-24