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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Many thanks for your contribution. I was looking for a solution using Sed as I understood that Grep could not provide one! Tell that to Memorek! Both your solutions worked perfectly. The Sed one, however, wasn't half convoluted! Yet, whenever someone says something can't be done, someone else says hold on a minute I've just done it!
Hi Turbocapitalist,
Thank you very much. Your response does exactly what I was looking for. I have not had any previous involvement with Awk as I was given to understand that it was a difficult language to master. It looks very powerful.
Your help is much appreciated.
No problem. Be sure to consider the comments on that method in #4 and #5 above. I left the grep in there because it wasn't clear what kind of pattern you were searching for, say if it was a PCRE expression. In most other cases you can fold the pattern into AWK and skip grep completely. There are also a lot of built-in variables like FILENAME which can help.
As for mastering the language, that would take a long while but the basic orientation as to what it's good at and how to use it can be acquired in an hour or two of concentrated study.
Hi Shruggy, thank you for drawing my attention to that. On the same note, if I wanted Grep to cycle through all the files in the Z2 directory and also any other sub directories within the Z2 directory, is that doable? If so, how would I code it?
Thank you
Hi Shruggy, thank you for pointing this out to me. On that point, how do I code it if I wish Grep to cycle through all the files in directory Z2 including any sub directories? Using /media/sda3/Z2/*.* doesn't seem to work. Sda3 is my data drive.
Hi MadeinGermany, thank you for your suggestion. To be honest I hadn't thought any wider than files in a particular directory. I had not considered that there might also be sub directories involved. I have run your Grep -R suggestion and it works perfectly. I appreciate your contribution very much.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.