AWK,与四位启动打印线 [英] awk, print lines which start with four digits
本文介绍了AWK,与四位启动打印线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要打印从文件随四位数字开头的行。我想这allredy,但它不工作:
猫的data.txt | AWK --posix'{如果($ 1〜/ ^ [0-9] {4} /)打印$ 1}
不产生输出
下一行打印它以数字开头的所有Lins的:
猫的data.txt | AWK --posix'{如果($ 1〜/ ^ [0-9] /)打印$ 1}
解决方案
通过awk的:
$的awk'/ ^ [0-9] [0-9] [0-9] [0-9] / {$打印1}your_file
这是,检查4位首发就行了。
更新:5个字符不是一个数字
$ AWK'/^[0-9][0-9][0-9][0-9]([^0-9].*)?$/ {打印$ 1}your_file
请注意这是没有必要使用 {如果($ 1〜/ ^ [0-9] /)
句,它与刚刚 /^.../
。
I want to print all lines from a file which begin with four digits. I tried this allredy but it does not work:
cat data.txt | awk --posix '{ if ($1 ~ /^[0-9]{4}/) print $1}'
No output is generated
The next line prints all lins which start with a number:
cat data.txt | awk --posix '{ if ($1 ~ /^[0-9]/) print $1}'
解决方案
With awk:
$ awk '/^[0-9][0-9][0-9][0-9]/ {print $1}' your_file
that is, check for 4 digits starting the line.
Update: 5th character not to be a digit.
$ awk '/^[0-9][0-9][0-9][0-9]([^0-9].*)?$/ {print $1}' your_file
Note it is not necessary to use the { if ($1 ~ /^[0-9]/)
sentence, it is done with just /^.../
.
这篇关于AWK,与四位启动打印线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文