awk condition for 30th column of a line is not working

85 Views Asked by At

My Input file looks like below,

1,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,,kapeta,,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,C
2,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,20181006T11:57:13+0100,,vsuser,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,H
1,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,,enrruac,,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,C
4,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,20181007T22:25:13+0100,,vsuser,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,H

i want to print only the line that are starting with '1' and ends with 'C', so i am trying with below command,

awk -F, '$1=='1' && $31=='C'{print $0}' input_file.txt

but i am not getting any output.

2

There are 2 best solutions below

1
On

Use double quotes:

awk -F, '$1=="1" && $31=="C"{print $0}' file

or

awk -F, '$1=="1" && $31=="C"' file 
1
On

As other users suggested, this can be done using a simple regex. So you can use sed as well as awk

sed '/^1,.*,C$/!d' file