我的输入文件如下所示,
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
我只想打印以'1'开头并以'C'结尾的行,所以我尝试使用以下命令,
awk -F, '$1=='1' && $31=='C'{print $0}' input_file.txt
但是我没有任何输出。
答案 0 :(得分:3)
使用双引号:
awk -F, '$1=="1" && $31=="C"{print $0}' file
或
awk -F, '$1=="1" && $31=="C"' file
答案 1 :(得分:1)
正如其他用户建议的那样,可以使用简单的正则表达式来完成。所以您可以使用sed以及awk
sed '/^1,.*,C$/!d' file