Operating System - Linux
1753784 Members
7225 Online
108799 Solutions
New Discussion юеВ

Re: Need some help with text manupulation

 
SOLVED
Go to solution
Senthil Kumar .A_1
Honored Contributor

Need some help with text manupulation

Filename active.txt is the original file and Filename active.new.txt contains the desired o/p.

In the file ALPHA , BETA , KAPPA are the group names and the ip address and other text just below these group names are specs related to them.

ALPHA <--- group name
169.0.1.6:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD <---spec data
169.0.1.8:KRCJFWRT01:KRCJFWRT01:HGYUE9054256NFVD <---spec data

BETA
169.0.1.9:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD
169.0.1.10:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD

Could you please help me make a script which can take the file active.txt as input file like below:

cat active.txt

and perform some editing on the file such that
the the group name which is over the top of the spec data should get embedded with each line of spec data . like this


ALPHA:169.0.1.6:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD
ALPHA:169.0.1.8:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD

BETA:169.0.1.9:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD
BETA:169.0.1.10:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
2 REPLIES 2
Steve Lewis
Honored Contributor
Solution

Re: Need some help with text manupulation

awk -F: '{if(NF==1)g=$1;if(NF>1)printf("%s:%s\n",g,$0)}' active.txt

gives this:
ALPHA:169.0.1.6:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD
ALPHA:169.0.1.8:KRCJFWRT01:KRCJFWRT01:HGYUE9054256NFVD
BETA:169.0.1.9:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD
BETA:169.0.1.10:HSJFNEI43:HSJFNEI43:HGYUE9054256NFVD


Senthil Kumar .A_1
Honored Contributor

Re: Need some help with text manupulation

Thanks Steve, Your response was right on target.
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)