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!

Beginner question here.. 3

Status
Not open for further replies.

BIS

Technical User
Jun 1, 2001
1,893
NL
Hallo All,
Apologies if this is exceedingly obvious.

Suppose I have a file conatining:

some text here
Result1: OK
Result2: OK
some more text here

how would I find and replace Result1 and Result2 with Results? So that the end result would look like:

some text here
Results: OK OK
some more text here

 
Try...
Code:
/Result/ {r = r " " $2; next} 
r {print "Results:" r; r=""}
{print}
 
Many thanks. Actually the part I need is like this (sorry should have posted that).

some text here
First Name: John
Last Name: Doe
some more text here

and I would like to get:

some text here
Name: John Doe
some more text here

so the above construck /Result/ wont work. Any ideas?
 
Code:
/^(First|Last) Name/ {r = r " " $3; next}
r {print "Name:" r; r=""}
{print}
 
futurelet,

Could you explain the

r {print "Name:" r; r=""} part?

I am trying to get a result that looks like this:

<Name:> John Doe </Name:>

I can get:

<Name:> John Doe

But I can't seem to figure out how to add the last part...
 
HAve you tried to replace this:
r {print "Name:" r; r=""}
By this ?
r {print "<Name:>" r "</Name>"; r=""}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks - just realized that :)
This works great. Many thanks to everyone here - much appreciated.

Just out of curiosity, what does the last r="" do? Resets the variable r?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top