![]() |
Attempting to append a line of text to the end of the previous line
Hi all,
This is my first post on this forum. I need to append a line of text to the end of the previous line. My data is as follows: device hostname user user01 show * deviceid:6d41fc OK device hostname user user02 show * deviceid:d8c18e OK device hostname user user03 show * deviceid:abd00d OK I need it in the following format and there are a few thousand lines of this: device hostname user user01 show * deviceid:6d41fc OK device hostname user user02 show * deviceid:d8c18e OK device hostname user user03 show * deviceid:abd00d OK or even better: device hostname user user01 show * deviceid:6d41fc device hostname user user02 show * deviceid:d8c18e device hostname user user03 show * deviceid:abd00d Can anyone help with this? |
Welcome to LQ!!
What have you tried? Once we know where you are, it's easier to give the right kind of advice. SED will do this, and I'm pretty sure AWK will also. With SED, the basic drill is this: when you see "device hostname", send the line to the hold register(h), get the next line, and append to the hold register (H) Then, get (g) the contents of hold, strip out the "\n" (newline), and print The final command would key off of "OK" and simply remove the line. Really good SED tutorial here: http://www.grymoire.com/Unix/Sed.html |
Thanks pixellany,
I haven't really tried anything once I got to this stage as I was stumped. I'm new to Linux or at least text manipulation within Linux so I'm not familiar with sed or awk. I had never heard of sed until your post. vi is the only editor I've used but not in any great detail. |
OK.....
SED and AWK are two traditional Unix "power tools". They even have their own O'Reilly book ("SED and AWK"). The site I linked has a lot of good stuff--not just SED. You also might want to look at the Bash Guide for Beginners---free at http://tldp.org What can we do to be of further assistance? |
Thanks a lot. I'm currently looking through the SED tutorial to work out how to get the text in the file into the format I require. Thanks again.
|
| All times are GMT -5. The time now is 12:14 PM. |