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!

Adding Text to Selected Lines (Revisited) 1

Status
Not open for further replies.

thunderkid

Technical User
Oct 26, 2000
54
US
I need to create new file as follows:
Input:

34567645
abc 0:01:41.0 2345 rt45
abc 0:01:42.0 2345 rt45
abc 0:02:03.0 2345 rt45
abc 0:03:04.0 2345 rt45
56753434
def 0:03:05.0 erte wfe5
def 0:03:06.0 erte wfe5
def 0:04:07.4 erte wfe5
def 0:05:08.5 erte wfe5

Desired output:

34567645 abc 0:01:41.0 2345 rt45
34567645 abc 0:01:42.0 2345 rt45
34567645 abc 0:02:03.0 2345 rt45
34567645 abc 0:03:04.0 2345 rt45
56753434 def 0:03:05.0 erte wfe5
56753434 def 0:03:06.0 erte wfe5
56753434 def 0:04:07.4 erte wfe5
56753434 def 0:05:08.5 erte wfe5

The following script was suggested for similar task, but I have not been able to modify it to work for task above. I have tried several variations on the scripts, but have not been able to get to the desired output I need.

awk '
/Seed /{Seed=$NF;next}
{print Seed " " $0}
' /path/to/input >output

Need of help,
thunderkid
 
Try this:
Code:
awk '
NF==1{Seed=$1;next}
{print Seed " " $0}
' /path/to/input >output

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