ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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 cannot see what the code is supposed to be doing. For example, you have several variables being set to the same passed argument ($2), but it's not obvious what gets passed as $2. (To find out, insert a print statement to just print out that variable.)
Why would you set several different variables to the same value?
Why would you not extract the data needed using AWK's field syntax?
I cannot see what the code is supposed to be doing. For example, you have several variables being set to the same passed argument ($2), but it's not obvious what gets passed as $2. (To find out, insert a print statement to just print out that variable.)
Why would you set several different variables to the same value?
Why would you not extract the data needed using AWK's field syntax?
to this format:
dn:cn:sn:givenName:MailisplayName
cn=10,ou=work,o=dom.com:denis.vezina@dom.com:vezina:denis:denis.vezina@dom.com:denis vezina
cn=20,ou=work,o=dom.com:jean.paul@dom.comaul:jean:jean.paul@dom.com:jean paul
cn=30,ou=work,o=dom.com:isabelle.didi@dom.com:didi:isabelle:isabelle.didi@dom.com:isabelle didi
cn=40,ou=work,o=dom.com:alain.papa@dom.comapa:alain:alain.papa@dom.com:alain papa
If you chek my previous result, you will notice that the cn filed is missing and the first field is not matching with the other data.
I think that ghostdog's point is that ":" needs to be in your field separator (FS) list. I think you might also want to include a blank, but that could "mess up" the name parsing. Perhaps you'd want to strip leading and trailing blanks (if any) from $2.
While setting the record separator (RS) to null, as he suggests, will let you parse the whole set as a single record, I don't think his suggested program would scale very well to a long file.
To drop all the spaces, just pipe the data thru a SED command:
<existing code> | sed 's/ //g' > newfilename
Do you have a good book on shell scripting? You can get "Bash Guide for Beginners" free at http://tldp.org. Also, go here for really good tutorials: http://www.grymoire.com/Unix/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.