0

I have a csv file looks like this:

aaa,vvv,,,,
bbb,qqq,,,vvv,
ccc,www,iii,,,kkk
ddd,rrr,,,lll,
eee,ttt,ooo,sss,ggg,jjj
fff,yyy,ppp,,,

i want to get rows that nth to mth columns are empty (in this example:get rows that 3th to 4th are empty)

and then get output as follows

bbb,qqq,,,vvv,
ddd,rrr,,,lll,

Actually i want to get only rows that specific range columns are empty for example with awk

awk -F, '$n-$m=="" {print}' file.csv
awk -F, '$3-$4=="" {print}' file.csv
0

One way:

awk -F, -v st=3 -v end=4 '{for(i=st;i<=end;i++){if($i){next;}}}1' file
0

The awk solution by @Guru is probably much more portable than this, but using grep for this specific example:

egrep '^[a-z]*,[a-z]*,{3}[a-z]' csv 
bbb,qqq,,,vvv,
ddd,rrr,,,lll,

Where csv is this file:

cat csv
aaa,vvv,,,,
bbb,qqq,,,vvv,
ccc,www,iii,,,kkk
ddd,rrr,,,lll,
eee,ttt,ooo,sss,ggg,jjj
fff,yyy,ppp,,,

grep --version
grep (BSD grep) 2.5.1-FreeBSD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.