繁体   English   中英

Shell脚本和正则表达式(sed,awk,grep ...?)

[英]Shell scripting and regular expressions (sed, awk, grep…?)

假设我有一个看起来像这样的文件:

user ID   time started  time ended yes/no 
3523         15:00          0        yes  
2356         12:13       12:18       yes  
4690         09:10          0        no  

我想编写一个shell脚本,它将选择文件中所有时间为“ 0”和“是”的行。

对于此示例,它仅是第一行:

3523     15:00       0        yes  

awk '$3 == "0" && $4 == "yes" { print; }' myfile

这也将工作

grep '............................0........yes' myfile

grep -E '^[^ ]+ +[^ ]+ +0 +yes$' inputfile

要么

grep -E '^([^ ]+ +){2}0 +yes$' inputfile

要么

sed -n '/^\([^ ]\+ \+\)\{2\}0 \+yes$/p' inputfile

要么

sed -nr '/^([^ ]+ +){2}0 +yes$/p' inputfile

这可能对您有用:

 sed '/\s0\s\+yes\s*$/!d' inputfile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM