Scripting question

Jonathan McKeown jonathan+freebsd-questions at hst.org.za
Thu Sep 13 13:34:13 PDT 2007


On Thursday 13 September 2007 20:19, Kurt Buff wrote:
> On 9/13/07, Jerry McAllister <jerrymc at msu.edu> wrote:
> > > The only space is the one separating the SMTP address from the OK or
> > > NO.
> >
> > Then you should be able to tell it to sort on the first token in
> > the string with white space as a separator and to eliminate
> > duplicates.   It has been a long time since I had need of sort. I
> > don't remember the arguments/flags but am sure that type of thing can be
> > done.

You can use uniq if the file is already sorted (if not, put a sort at the 
start of the pipe) - after using awk to pick the first field:

awk '{print $1}' inputfile | uniq -u

> Ya know, it's really easy to get wrapped around the axle on this stuff.
>
> I think I may have a better solution. The file I'm trying to massage
> has a predecessor - the non-unique lines are the result of a
> concatenation of two files.
>
> Silly me, it's better to 'grep -v' with the one file vs. the second
> rather than trying to merge, sort and further massage the result. The
> fix will be to use sed against the first file to remove the ' NO',
> thus providing a clean argument for grepping the other file.

If it's two files and you want to select or reject common lines, look at 
comm(1) as another technique.

Jonathan


More information about the freebsd-questions mailing list