Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Content of File Alphebetically 1

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a file with contents that I need sorted alphebetically by the first character on each line starting with A-Z. The file name is cmd_out and should be outputed to a new file called cmd_out_sorted.

I also need to remove duplicate strings first. I tried uniq -u , but it still leaves some duplicates. The contents look like:

<imlct:spg=0;
:mcsap:file=tlogio,io1=all,sdate=20020516,stime=0800;
:end;
ALLIP;
ALLIP;
ALLIP;
ALLIP;
RXMFP:MO=RXOCF-39;
IMLCT:SPG=0;
<imlct:spg=0;
:mcsap:file=tlogio,io1=all,sdate=20020515,stime=0800;
:end;
DBTSP:TAB=AXEPARS,SETNAME=CME20BSCF,NAME=ADAPTIVECONFIG;
DBTSP:TAB=AXEPARS,SETNAME=CME20BSCF,NAME=AUTOHFSEXPAND;
ALLIP;
DBTSP:TAB=AXEPARS,SETNAME=CME20BSCF,NAME=DYNHRALLOC;
DBTSP:TAB=AXEPARS,SETNAME=CME20BSCF,NAME=DYNOLULSC;
DBTSP:TAB=AXEPARS,SETNAME=CME20BSCF,NAME=G1GSMBAND;
DBTSP:TAB=AXEPARS,SETNAME=CME20BSCF,NAME=GPRS;
DBTSP:TAB=AXEPARS,SETNAME=CME20BSCF,NAME=HCS;
DBTSP:TAB=AXEPARS,SETNAME=CME20BSCF,NAME=HCSBAND;



Thanks for the help as always!
Beaster
 
Never mind this request, I decided it is not really what I want, Thanks, Beaster
 
Hi,
sort -u file > sortedfile


will do both the sort and removing duplicates at the same time.

sort file | uniq > sortedfile

uniq assumes the file is sorted and only remove duplicates lines if they are followed by the exact same duplicate line.

with a file like

a
b
a

uniq won't know the 'a' is a duplicate because it is proceeded by a 'b'. but if you sort it first so you have

a
a
b

uniq will remove the duplicate a.


Also you should realize uniq -u will only return lines which are not duplicates. therefore

a
b
a

sort file | uniq -u

would actually produce an output of just

b

uniq -d will produce just the output of the duplicate lines.

sort file | uniq -d

would produce an output file of just duplicate lines

a


------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top