Solved

Need help with grep command pattern

Posted on 2013-07-01
2
374 Views
Last Modified: 2013-07-01
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?
0
Comment
Question by:YZlat
2 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 250 total points
ID: 39290901
So close...  :)

grep "^[a-zA-Z][a-zA-Z0-9]*:.*:A" foo | while read LINE
do
echo $LINE
done
                                 
Try that one.  After the initial alpha, any alphanumeric should be allowed.


Kent
0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 39290963
You nailed it!:)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now