Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Originally Posted by sharath.bv
Please check if the below syntax truely satisfies the given conditions...
You must try it and see. Create a sample file with lines of text, some of which have the pattern and some of which don't. Use your search pattern and see what it finds. Then you will see that it does not meet the conditions described in your first post.
Then try mine. I think it does, but there was some slight ambiguity in your conditions. I interpreted them to mean that commas separated all the elements.
This sounds like homework, but your posting history says maybe not....
This is the kind of thing where you have to be very careful to test all possible outcomes. For example, where can the commas be? ..between the numbers or also between the letters and numbers? Also, how many numbers are possible?
Here's one example (used with SED)
sed -r 's/[0-9],?[0-9][a-z][0-9],?[0-9]/ZZZ/g' filename (Looks for the match and replaces all instances with "ZZZ".)
Translation: match any digit, followed by optional comma, another digit, a letter, another digit, optional comma, and another digit. Add one more comma in there, or a 2-digit number and it won't match.
To match any number of digits and optional commas, things will obviously get a bit trickier. The best way to proceed is to write something simple and test it. Then keep adding to it until it behaves the way you want.