awk - Removing lines with the first and the last occurence of a column value -


i have following file

    id      score    other     abr     0.98     nbnmsb     bcg     0.76     nbnmsb     cvd     0.6      nbnmsb     bcg     0.9      vscva     cvd     0.56     vscva     abr     0.9      vscva     cvd     0.7      bavsc     bcg     0.4      bavsc     abr     0.5      bavsc     aac     0.1      bavsc     abr     0.8      nbnmsb     bcg     0.6      nbnmsb     cvd     0.3      nbnmsb     bcg     0.7      vscva     cvd     0.0      vscva     abr     0.1      vscva     cvd     0.5      bavsc     bcg     0.8      bavsc     abr     1.0      bavsc 

and want exclude first , last occurrence of value in column 3 such output as:

id      score    other bcg     0.76     nbnmsb cvd     0.56     vscva bcg     0.4      bavsc abr     0.5      bavsc bcg     0.6      nbnmsb cvd     0.0      vscva bcg     0.8      bavsc 

if have tac (or gtac) can remove first instances, reverse file, remove first (really last) instances , flip file 1 last time.

$ awk '$3==p;{p=$3}' file1 | tac | awk '$3==p;{p=$3}' | tac bcg     0.76     nbnmsb cvd     0.56     vscva bcg     0.4      bavsc abr     0.5      bavsc bcg     0.6      nbnmsb cvd     0.0      vscva bcg     0.8      bavsc 

edit:

here more flexible version. set initial value of c desired column:

use column 3:

 c=3 && awk -v c=$c '$c==p;{p=$c}' file1 | tac | awk -v c=$c '$c==p;{p=$c}' | tac 

use column 4:

 c=4 && awk -v c=$c '$c==p;{p=$c}' file1 | tac | awk -v c=$c '$c==p;{p=$c}' | tac 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -