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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -