Link to home
Start Free TrialLog in
Avatar of Valleriani
VallerianiFlag for Sweden

asked on

Linux Sort/Dedupe but with a header on line 1

I have the following command:

sort FILENAME -u >> FILENAME-2


What it is meant to do is DEDUP AND SORT. However, my files have a one line header at the top; EX.

Email,Fname,Lname
rvalleriani@test.com,Chris,Valler
test@test.com,Mike,Liuk
m@m.com,Maurico,Hammer


The above command will randomize everything including the first line, which it shouldn't do!!

I was told to try this:

tail +2 FILENAME| sort FILENAME -u >> FILENAME-2

However, this doesn't seem to work either.

Any suggestions?
Avatar of farzanj
farzanj
Flag of Canada image

try this

sed -n '2,$p' FILENAME | sort -u > FILENAME2
Avatar of Valleriani

ASKER

Hello!

Instead of keeping it, it actually removes the first line so

email
aaa
zzz
bbb

becomes

aaa
bbb
zzz

with no header.
I've requested that this question be deleted for the following reason:

I have gotten the answer, sorry about that, here it is though:<br /><br />gawk 'NR==1; {if(NR &gt; 1) {print $0 | &quot;sort -u&quot;}}' f_edit.txt &gt;&gt; f_edit2.txt
ASKER CERTIFIED SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Would the last one work for you?
When you ask a question, you have to be patient.  People spend time in providing you a solution and you simply waste their time.
echo -e $(head -1 FILE)"\n$(sed -n '2,$p' FILE | sort -u)" works as well by farzanj, actually , I had submitted an ticket but apparently, I didn't realize there is an object button.