LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Text file manipulation: alphanumeric strings (https://www.linuxquestions.org/questions/linux-newbie-8/text-file-manipulation-alphanumeric-strings-739164/)

CHARL0TTE 07-10-2009 07:51 AM

Text file manipulation: alphanumeric strings
 
Hi,

I am just getting to grips with writing my first shell script, but have got stuck on what is probably something fairly straightforward. Hopefully you can help.

I have a text file which contains some lines of interest and many lines which are not required, so I've been using egrep and awk to create a new output file containing only the lines of interest.

The problem I have is that I would like my file to include lines which contain alphanumeric codes like 'AB1r' but not 'AB1'. I have many different alphanumeric combinations in the same format, but am only interested in the lines that contain an alphanumeric code ending in lower-case r . Note, it is important that the whole line in which the alphanumeric code sits is selected, not just the alphanumeric code itself.

Can you help please?

Thanks,

Charlotte

Wim Sturkenboom 07-10-2009 08:14 AM

Code:

grep -E '[a-zA-Z]{2}[0-9]r' abc.txt
will find any line containing 2 characters (lowercase or uppercase) followed by 1 digit followed by 'r'.

Forgot: welcome to LQ

CHARL0TTE 07-10-2009 09:40 AM

Thank you Wim Sturkenboom, that works perfectly!

Best wishes to you.


All times are GMT -5. The time now is 06:33 AM.