LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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

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
CHARL0TTE
LQ Newbie
 
Registered: Jul 2009
Posts: 14

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

Best wishes to you.
 
  


Reply


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


All times are GMT -5. The time now is 11:20 AM.

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