r - Remove lines based on duplicate values -



r - Remove lines based on duplicate values -

i have bash file 2 fields.

eg:

abc 0.23 bca 2.30 azs 1.23 cda 2.11 xds 0.45 abc na cda na ang na

there 2 duplicates in first column abc , cda. both these duplicates have na in sec column. want remove lines have duplicates remove 1 has na in sec while retaining others.

desired output:

abc 0.23 bca 2.30 azs 1.23 cda 2.11 xds 0.45 ang na

i tried r output messy. hope there improve way in bash file around 40000 lines.

thanks!

here's 1 solution using awk:

awk '( !($1 in val) || $2 != "na" ) { val[$1] = $2 } end { (k in val) { print k" "val[k] } }'

output:

cda 2.11 abc 0.23 azs 1.23 ang na xds 0.45 bca 2.30

if need preserve order of lines, require more work.

r bash

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -