Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sed question 1

Status
Not open for further replies.
Apr 11, 2002
144
US
RH8 Linux using bash.

Is it possible to sed a line so that it "Shift-j"'s the end of the line?

sed 's/$/shift-j/' or something like that.

In other words, with vi I could "shift-j" a line and pull the line below up and add it to the current line. I'm greping lines containing BLOCK, but I need to also grab the 3 lines below and concatenate them all into one line.

Is this possible?


>Think for yourself<
...or someone else will do it for you.
 
paste -s will join lines, but you could use awk to search for BLOCK and join the subsequent lines. Not tested...

awk '/BLOCK/ {for(x=0;x<3;x++){printf $0 &quot; &quot;;getline}; print $0}' $FILE

 
Ygor you rock!
Works great.


>Think for yourself<
...or someone else will do it for you.
 
Although solved well, you can still use sed. Such as appending the empty hold space to the pattern space. E.g.

sed 'G' $FILE



Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top