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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Match part of line and move to replace part of following line

Status
Not open for further replies.
Apr 8, 2014
13
US
Given a file:
Code:
penguin giraffe zebra green
blue bear puppy duck kitty
orange grape lamb koala purple

Move part of the text on a line to the next line in a specific place.

Code:
penguin giraffe zebra green
blue bear duck kitty
orange grape puppy koala purple

In this case puppy is moved from line 2 to replace lamb in line 3.

This attempt yields nothing:
Code:
sed 's/\(.*\)\(puppy\)\(.*\)/{H;\2}/' -e 's/\(.*\)\(lamb\)\(.*\)/\1{g;p}\3/' text
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top