I have an output from Unix uniq -c
command which prints the number of occurrences of a string at the beginning of each line. The string represents two authors separated by a pipe (e.g., Aabdel-Wahab S|Abdel-Hafeez EH
).
1 Aabdel-Wahab S|Abdel-Hafeez EH
1 Aabdel-Wahab S|Abdulla AM
4 Aabdel-Wahab S|Ahmad AK
1 Aabdel-Wahab S|Mosalem FA
1 Aabye MG|Andersen AB
8 Aabye MG|Changalucha J
1 Aabye MG|Christensen DL
1 Aabye MG|Faurholt-Jepsen D
I need to grep the occurrence number and move it to the end of the line. For example:
Aabdel-Wahab S|Abdel-Hafeez EH|1
Aabdel-Wahab S|Abdulla AM|1
Aabdel-Wahab S|Ahmad AK|4
Aabdel-Wahab S|Mosalem FA|1
Aabye MG|Andersen AB|1
Aabye MG|Changalucha J|8
Aabye MG|Christensen DL|1
Aabye MG|Faurholt-Jepsen D|1
Please note that frequencies are now pipe delimited. Pasted below is my one-liner in Awk:
awk '{num=$1;$1=""; sub(/^ /,""); print $0,"|",num;}' file
However the Awk add extra spaces around the final pipeline:
Aabdel-Wahab S|Abdel-Hafeez EH | 1
Aabdel-Wahab S|Abdulla AM | 1
Aabdel-Wahab S|Ahmad AK | 4
Aabdel-Wahab S|Mosalem FA | 1
Aabye MG|Andersen AB | 1
Aabye MG|Changalucha J | 8
Aabye MG|Christensen DL | 1
Aabye MG|Faurholt-Jepsen D | 1
Any idea how to proceed (not necessary using Awk)?