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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl sort one-liner in DOS bat 1

Status
Not open for further replies.

chibaru

Programmer
Aug 24, 2005
13
US
Hi,

Is it possible to have a Perl one-liner sort that will produce no duplicate records in a DOS bat file? The files are defined in the job environment (local) variables. I tried different variations of the following with no success:

perl -pe "sort $ENV{qq(INSORT)} | uniq -u > $ENV{qq(OUTSORT)}"

I appreciate any help you can give.

Thanks!!!
 
Try this:

Code:
perl -ne "$h{$_}=1; END { print sort keys %h; }" %INSORT% > %OUTSORT%

It assigns 1 to a hash indexed by the input lines (which by definition must be unique), and then at the end prints out the keys of that hash, sorted.

Annihilannic.
 
You may net to change %h to %%h to put it in a .BAT file (the above code works from the command line).

Annihilannic.
 
Thank you Annihilannic!! I am not so good with hashes. You really saved me a lot of time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top