에이바바
에이바바

Reputation: 1031

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'.

For this example it'd be the first line only:

3523     15:00       0        yes  

Upvotes: 1

Views: 2860

Answers (4)

Ash
Ash

Reputation: 355

this will work as well

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

Upvotes: 1

potong
potong

Reputation: 58473

This might work for you:

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

Upvotes: 1

Dennis Williamson
Dennis Williamson

Reputation: 360325

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

Upvotes: 1

jtdubs
jtdubs

Reputation: 13983

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

Upvotes: 3

Related Questions