Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-10-2009, 08:51 AM   #1
LQ Newbie
Registered: Jul 2009
Posts: 14

Rep: Reputation: 0
Text file manipulation: alphanumeric strings


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?


Old 07-10-2009, 09:14 AM   #2
Wim Sturkenboom
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
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

Last edited by Wim Sturkenboom; 07-10-2009 at 09:16 AM. Reason: added welcome
1 members found this post helpful.
Old 07-10-2009, 10:40 AM   #3
LQ Newbie
Registered: Jul 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Thank you Wim Sturkenboom, that works perfectly!

Best wishes to you.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy string/text manipulation/indentation for restructured text brianmcgee Linux - Software 1 04-22-2008 09:27 PM
How to store text(strings) in a 2D character array reading from a text file(C++) bewidankit Programming 3 02-14-2008 08:08 AM
need help with text manipulation pcorajr Programming 12 12-15-2006 08:33 AM
More text manipulation ice_hockey Linux - General 2 05-28-2005 02:43 AM
Using c++ to write to a text file. Im having problem with strings swatward Programming 4 02-03-2005 10:17 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:33 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration