Bash – How to print lines with blank 5th field in CSV

awkbashtext processing

I have to check if the fifth field is empty in a CSV file. This is my file:

1,abc,543,87,DATA,fsg; 
1,abc,543,87,,fsg; 
1,abc,543,87,DATA,fsg; 
1,abc,543,88,,fsg; 
1,abc,543,,DATA,fsg; 

As you can see, the second and fourth lines have an empty fifth field. I want to print all these lines.

Result should be this:

1,abc,543,87,,fsg;
1,abc,543,87,,fsg; 

Best Answer

Another awk:

$ awk -F, '!length($5)' file
1,abc,543,87,,fsg; 
1,abc,543,88,,fsg;
Related Question