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

string editing - convert to one liner with insertions 1

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
Hello,

my input is...
S Arnold and DJ Harper
K Harrison
J Summer
R Shank

I need a one line output as follows...
S Arnold and DJ Harper, K Harrison (TV), K Summer (Referee), R Shank (Reserve)

thanks a ton!
Arun
 
Code:
sed '3s/\(.*\)/ \1 (Referee)/;' file | tr "\n" ","
This will change line 4 (substitute) and tr (translate) changes the linebrakes to comma.

The sed-command may be combined with others, separated by ;
Code:
sed '3s/\(.*\)/ \1 (Referee)/;2s/\(.*\)/ \1 (TV)/;' file | tr "\n" ","

The last step is left as an excercise to the reader.

don't visit my homepage:
 
Hi

Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

* [navy]Thank stefanwagner
for this valuable post![/navy]


at the bottom of stefanwagner's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
 
Thanks Feherke,
Done! Will follow in the future...
Arun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top