Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

Need help with grep command pattern

I have an input file that consists of many lines, each divided on 3 parts by colon:

test:wwwww:A
test2:nnnnnn:B
TEST3:qqqqqq:A
*test4:wwwww:C

I need to retrieve those lines that start with an alphanumeric character either upper case or lowercase and might have a digit anywhere in the middle of the string or at the end, and those that have its thord part equal to A. The line cannot start with a digit, *, # or any other character besides letters

For exaple from the sample lines above my code would need to return:

test:wwwww:A
TEST3:qqqqqq:A

Here is what I got:

grep "^[a-zA-Z]*:.*:A" foo | while read LINE
do
echo $LINE
done

Open in new window


But it returns only:

test:wwwww:A

grep "^[a-zA-Z][0-9]:.*:A" foo | while read LINE
do
echo $LINE
done

Open in new window


Does not return anything.

grep "^[a-zA-Z]*[0-9]:.*:A" foo | while read LINE
do
echo $LINE
done

Open in new window


only returns

TEST3:qqqqqq:A

and it would ignore any line with a digit in the middle of a string:
TE3T:qqqqqq:A



Can anyone help to fix my pattern?
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

You nailed it!:)