SED delete csv column if exists

With perl

$ perl -F'\t' -lane '@non_ref_cols = grep { $F[$_] ne "REF" } 0..$#F if $. == 1;
                     print join "\t", @F[@non_ref_cols]' ip.txt
GENE    ALT
AKT     G
AKT     G
  • -F'\t' use tab as field separator
  • @non_ref_cols = grep { $F[$_] ne "REF" } 0..$#F if $. == 1 for the header line, get index of all fields that is NOT REF
  • print join "\t", @F[@non_ref_cols] print all fields using the index array we got for the header line, using tab as field separator

Hi with miller (http://johnkerl.org/miller/doc) and this input.csv

GENE,REF,ALT
AKT,A,G
AKT,G,G

is very easy

mlr --csv cut -x -f REF input.csv

The output is

GENE,ALT
AKT,G
AKT,G

Tags:

Csv

Sed

Delete