本文介绍了AWK子字符串一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
substr函数的第三个参数为长度字符串.
print是awk中的默认操作.
substr function's 3rd argument is length of the string.
print is default action in awk.
这是columns.txt
Here is columns.txt
aaa bbb 3 ccc ddd 2 eee fff 1 3 3 g 3 hhh i jjj 3 kkk ll 3 mm nn oo 3我可以找到第二列以"b"开头的行:
I can find the line where second column starts with "b":
awk '{if(substr($2,1,1)=="b") {print $0}}' columns.txt我可以找到第二列以"bb"开头的行:
I can find the line where second column starts with "bb":
awk '{if(substr($2,1,2)=="bb") {print $0}}' columns.txt为什么为什么我找不到第二列中第二个字符是"b"的行?:
Why oh why can't I find the line where the second character in the second column is "b"?:
awk '{if(substr($2,2,2)=="b") {print $0}}' columns.txtawk -W version == GNU Awk 3.1.8
awk -W version == GNU Awk 3.1.8
推荐答案您可以使用:
awk 'substr($2,2,1) == "b"' columns.txt aaa bbb 3
更多推荐
AWK子字符串一个字符
发布评论