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.
Thanks guys, I have tested works great. I had some garbage in my text it looks like that's where I got stuck but manually fixed those...for now it does the job well. Appreciated everyone.
I tried awk,sed,perl versions above but none did work for the desired output.
You've been trying since July???.....
When you say that something does not work, it's best to describe exactly what happens or does not happen.
The code I gave you works for the original example--to wit: put the second line in front of the first, 4th in front of the third, etc.
Your current example (2nd line after the 1st) should also be pretty straightforward with SED---it will be a relatively small change to what I had before.
When you say that something does not work, it's best to describe exactly what happens or does not happen.
The code I gave you works for the original example--to wit: put the second line in front of the first, 4th in front of the third, etc.
Your current example (2nd line after the 1st) should also be pretty straightforward with SED---it will be a relatively small change to what I had before.
Hi - No, it was working for that file ...I was working on something new.... Pls give me sometime; I will retest it....
Hi - No, it was working for that file ...I was working on something new.... Pls give me sometime; I will retest it....
Hi Again ... Using sed I get this error:
sed: command garbled: /cquestion/{h;n;G;s/\n/,/p}
perl was working for a smaller file... but for this one that about 250k lines...doing nothing but printing the same file.....
can you please help ?
example:
INPUT:
dn: uid=AAAA,ou=abcd,o=abc.com
cquestion: Where is your favorite vacation spot?
dn: uid=BBBB,ou=abcd,o=abc.com
cquestion: Where is your favorite colour?
dn: uid=CCCC,ou=abcd,o=abc.com
cquestion: What is your last name?
ouput should be like:
dn: uid=AAAA,ou=abcd,o=abc.com,cquestion: Where is your favorite vacation spot?
dn: uid=BBBB,ou=abcd,o=abc.com,cquestion: Where is your favorite colour?
dn: uid=CCCC,ou=abcd,o=abc.com,cquestion: Where is your last name?
You would need to post the complete command you used.
BUT---that command I gave you is not what you want now (because you now want things in a different order)
First, let's look at what the original does:
Quote:
sed -n '/link/{h;n;G;s/\n/,/p}' filename > newfilename
Translation:
-n (suppress printing)
/link/ (for lines containing "link")
h (copy the line to the hold register)
n (get the next line)
G (recall the line from the hold register and append it to what you just read)
<<at this point we have detected the line containing "link", gotten the next line, and then added the first one after it>>
s/\n/,/ (replace the newline char. with a ",")
p (print out the final result)
In your most recent example, you want to key on the line containing "dn", and then add the next line after. The code will be similar, but, instead of appending from the hold register to the working register (G), you'll want to append to the hold register (H)
Go all the way back to my original post and look at the link--it explains all this quite well.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.