Skip to content
Advertisement

How to print the last line of each ID?

I have a list of IDs (exon) each with multiple suffixes and I want to get the last line of each ID

Input:

NM_203_exon_19
NM_203_exon_20
NM_0217_exon_7
NM_0217_exon_8
NM_0217_exon_9
NM_91_exon_14
NM_91_exon_15
NM_91_exon_16
NM_91_exon_17

Desired output:

NM_203_exon_20
NM_0217_exon_9
NM_91_exon_17

Advertisement

Answer

tac INPUTFILE |awk -F'_' '!a[$1FS$2]++' |tac
NM_203_exon_20
NM_0217_exon_9
NM_91_exon_17
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement