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'.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.