YZlat
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:
But it returns only:
test:wwwww:A
Does not return anything.
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?
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
But it returns only:
test:wwwww:A
grep "^[a-zA-Z][0-9]:.*:A" foo | while read LINE
do
echo $LINE
done
Does not return anything.
grep "^[a-zA-Z]*[0-9]:.*:A" foo | while read LINE
do
echo $LINE
done
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER