[英]Shell scripting and regular expressions (sed, awk, grep…?)
Let's say I have a file that looks like this: 假设我有一个看起来像这样的文件:
user ID time started time ended yes/no
3523 15:00 0 yes
2356 12:13 12:18 yes
4690 09:10 0 no
I want to write shell script that will pick out all of the lines in the file that have a time ended of '0' and 'yes'. 我想编写一个shell脚本,它将选择文件中所有时间为“ 0”和“是”的行。
For this example it'd be the first line only: 对于此示例,它仅是第一行:
3523 15:00 0 yes
awk '$3 == "0" && $4 == "yes" { print; }' myfile
这也将工作
grep '............................0........yes' myfile
grep -E '^[^ ]+ +[^ ]+ +0 +yes$' inputfile
or 要么
grep -E '^([^ ]+ +){2}0 +yes$' inputfile
or 要么
sed -n '/^\([^ ]\+ \+\)\{2\}0 \+yes$/p' inputfile
or 要么
sed -nr '/^([^ ]+ +){2}0 +yes$/p' inputfile
这可能对您有用:
sed '/\s0\s\+yes\s*$/!d' inputfile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.