I have a file with two words on each row, using GREP i have to verify two conditions :
if first word begins with a specific letter, for example 'A'
same for second word but different letter, for example 'B'
i know how to do it verify it only for first word
grep '^A' file
But how to verify for second word ?
You can use awk:
awk '$1 ~ /^A/ && $2 ~ /^B/' file
In case you want to avoid use of regex you can use this awk:
awk 'index($1, "A")==1 && index($2, "B")==1' file
Here is a egrep command for same but prefer awk:
egrep '^A[^[:blank:]]*[[:blank:]]+B' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With