Ahmed Ayoub
Ahmed Ayoub

Reputation: 1

Using awk to print lines with a column matching certain characters

I want awk to print the line if the first two characters in field 7 are "R ". I tried this command and it didn't work:

cat file.txt | awk -F, '{if($7=="R *") print $0}'

Can anyone help me with this?

Upvotes: 0

Views: 1390

Answers (2)

Arjun Mathew Dan
Arjun Mathew Dan

Reputation: 5298

awk -F, '$7 ~ /^[ \t]*R /' file.txt

Assuming data are comma separated.

Upvotes: 0

Bent Blue
Bent Blue

Reputation: 166

Use the tilde sign and Regular Expressions (words that start with the letter 'R' and second is space)

cat file.txt | awk -F, '{if ($7 ~ /^R /) print $0;}'

Upvotes: 1

Related Questions