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!

Moving fields around

Status
Not open for further replies.

tekdime

Technical User
Feb 20, 2004
2
US
Greetings all. Wow, I can't believe there is an awk forum. But thank goodness there is.

I've read "Getting Started With Awk" ( But it doesn't have what I'm looking to do.

Basically I want awk to read this line
$1 $2 asdfBADNAMEasdf "bla bla bla" '(any number of bla bla bla's here) (GOODNAME)'endendend
and output this
$1 $2 asdfGOODNAMEasdf "bla bla bla" '(any number of bla bla bla's here)'endendend

I'd greatly appreciate any help or advice. Also, if there's a way to do this from a shell script or another command I wasn't aware of, please let me know. Thanks for your time.
 
You can try this as a starting point:
Code:
awk '{
 if(match($0,/.*([^)]*)'"'"'/)){
  good=substr($0,1,RLENGTH-2)
  match(good,/.*[(]/)
  good=substr(good,RLENGTH+1)
  $3="asdf"good"asdf"
  sub("[(]"good"[)]","",$0)
 }; print
}' /path/to/inputfile
More input examples is required to determine which BADNAME to replace.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top