I am looking for a perl command where lines starting with a string are printed. For example, if I wanted to print all lines starting with "1234", what would that command look like? Sed? Awk? Grep?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
perl -ne 'print if /^1234/'
or
sed -ne '/^1234/p'
or
awk '/^1234/'
or
grep '^1234'
or
ruby -ne 'print if /^1234/'
or even
python -c 'import fileinput;print "\n".join([l for l in fileinput.input() if l.startswith("1234")])'
回答2:
perl -ne'print if /^1234/' file
But most people would use grep
.
grep ^1234 file
Or on Windows
findstr /r ^1234 file
回答3:
For completion:
sed -ne '/^1234/p' somefile
awk '/^1234/{print}' somefile
grep '^1234' somefile