我的数据如下所示:
1xxxxxx file_name1
0xxxxxx file_name2
0xxxxxx file_name3
0xxxxxx file_name4
1xxxxxx file_name5
0xxxxxx file_name6
我只想打印第一列以“1”开头的文件名。
也就是说,
awk '{if($1 contains '1') then print $2}' file.txt
但是,我不知道如何实现比较语法
也许可以使用通配符方法?
awk '{if($1 == "1"*) then print $2}' file.txt
最佳答案
试试这个:
awk '$1~/^1/{print $2}' file.txt
您使用 匹配运算符
(~
) 检查第一列 ($1
) 以查找以 开头的行1
(/^1/
)。如果为真,则打印第二列的操作发生。
关于linux - C Shell 子串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22026862/