Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help with grep command pattern

Posted on 2013-07-01
2
Medium Priority
?
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

721 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