bash - Zero a column in a csv file with awk while skipping the header -
i 0 1 column of csv file. let's assume csv file looks this:
col1|col2|col3 v | 54| t | 25| f d | 53| f s | 04| t
using awk way, gives me want
command:
awk -f'|' -v ofs='|' '$2=0.0;7' input.csv > output.csv
the result
col1|0|col3 v |0| t |0| f d |0| f s |0| t
but notice column header has been zeroed trying avoid. tried skip first line awk command getting empty file
awk -f'|' -v ofs='|' 'nr<1 {exit} {$5=0.0;7}' input.csv > output.csv
what missing?
just apply rule 2nd line on nr>1 {}
:
$ awk -f'|' -v ofs='|' 'nr>1{$2=0.0}7' file col1|col2|col3 v |0| t |0| f d |0| f s |0| t
why wasn't approach awk -f'|' -v ofs='|' 'nr<1 {exit} {$5=0.0;7}'
working?
the expression nr<1{exit}
never true because nr @ least 1.
this means second expression {$5=0.0;7}
evaluated. $5=0.0
fine, 7
not printing want to, because print line need kind of print
instruction. work if moved 7
outside braces, evaluate true , record printed: awk -f'|' -v ofs='|' 'nr<1 {exit} {$5=0.0}7'
.
but wouldn't want. instead, may want nr==1 {next}
skip first line. however, prevent being printed:
$ awk -f'|' -v ofs='|' 'nr==1{next} $2=0.0;7' file v |0| t |0| f d |0| f s |0| t
Comments
Post a Comment