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

removing duplicate lines ignoring empty lines and lines with #

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL

hi,
how to achieve this without sorting input file?
only first occurrence of duplicates should stay.

following command found on a site does remove also empty lines and with #es which I don;t want to be removed.
perl -ni -e '$s{$_}++||print' file

so, lines like:

#####
(a whitespace)#(a whitespace)
(a whitespace)

should not be removed if such duplicates are found.







 
What about this ?
awk '!/^[ #]*$/ && ++s[$0]{next}1' file

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top