Valleriani
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?
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
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?
ASKER
Hello!
Instead of keeping it, it actually removes the first line so
email
aaa
zzz
bbb
becomes
aaa
bbb
zzz
with no header.
Instead of keeping it, it actually removes the first line so
aaa
zzz
bbb
becomes
aaa
bbb
zzz
with no header.
ASKER
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 > 1) {print $0 | "sort -u"}}' f_edit.txt >> f_edit2.txt
I have gotten the answer, sorry about that, here it is though:<br /><br />gawk 'NR==1; {if(NR > 1) {print $0 | "sort -u"}}' f_edit.txt >> f_edit2.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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.
sed -n '2,$p' FILENAME | sort -u > FILENAME2