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.
i) are you changing file names or file contents ?.
ii) show real data (several lines at least) and desired result - munged in need, but what the actual data looks like.
iii) what have you tried, and why are you having trouble.
Once again it will be helpful to advise LQ members what you have tried and what you have in mind for how to approach this.
You say "script". Do you have any experience writing scripts? And in which language?
Please describe in more detail the few things you have tried and a representation of the outcome. You say you cannot share more details about the files. A good thing to do here then is to share representative examples which are very close, or describe better.
The approach you've describe in your first post is somewhat helpful, however if these are passwords, then they may all be unique, they also may be non-printable binary, or they may be hashed information, once again making them all unique. Therefore people can recommend possible solutions like finding all strings containing "password=" and then adding your new bracketed string after it. And put a condition that you also can add your bracketed string at the end of the same line you modify. This all likely can be accomplished with a combination of a script, and using any, or all of sed, awk, or tr. The issue here is whether or not the representative descriptions shown are accurate enough and cover all search specs for strings you wish to modify.
It substitutes the string password= prefixed with only letters or - _ . characters.
It uses backreferences, i.e. \1 restores what matched in the 1st \( \) and so on.
Last edited by MadeInGermany; 03-27-2017 at 12:27 PM.
Did you properly enclose the sed expression in quotes?
Code:
sed 's/a/b/'
Also, it's best not to muck around as root. It's a good way to turn small mistakes into big accidents. So it is recommended to make a copy of the data and practice as an unprivileged user, then when you have the details worked out, then try it as root.
regex appeals to my perverse nature. Dunno how to teach that to anyone else ...
I learn by doing - learning how good people here did things, and trying out "what-if" thought games. For a long time I had this (or similar) pinned on my cubicle wall to keep me humble.
Also be aware that "regex ain't regex" - there are several forms, not all compatible with each other. And if you also have to deal with M$oft, that is a whole different ball-game - not that that's a surprise to anyone.
Many thanks to MadeInGermany, Turbocapitalist and syg00 !! Problem solved.
If I want to master this type of skill, kindly recommend any good book, tutorial that from your experience are excellent learning resources.
As mentioned, there are several variants of regular expressions. The main two you'll find are POSIX and Perl (aka PCRE or Perl-compatible Regular Expressions). You'll find those everywhere. There are two manual pages, which are ok as a reference but maybe not the place to start for learning:
Then you can move up to the more powerful and flexible Perl regular expressions. For those you pretty much have your choice of languages, if you aren't going to try perl first. Which language is your preference?
I agree with syg00 that there is no better way to learn regex stuff than just doing it again and again. Another thing I like to do is solve using option A (let us use sed as here) and then see if I can do the same with awk,perl,ruby,python or for something simpler, try and get the string you are looking for with grep (use standard and then if need be, use -E or -P to refine in different ways)
oh ... and the perverse thing .... ditto ... I just like the challenge
The Third Edition contains language-specific chapters on Perl (82 pages), Java (40 pages), .NET (34 pages), and PHP (46 pages). The first six chapters on general concepts take 282 pages. The table of contents, preface, index, etc. take up the remaining 50 pages.
The website contains more detail eg List of Contents etc.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.