1830909 Members
1709 Online
110017 Solutions
New Discussion

script help

 
SOLVED
Go to solution
Shabu Khan_1
Advisor

script help

Hi,
I've an input file with the following details:

SERVER1
AAAA:11111:BLAH BLAH:BLAH
bbbb:11111:BLAH BLAH:BLAH
#--------------------------#
SERVER2
STUFF:STUFF2:11111:TEST
#--------------------------#
....

and so on ...

I want to append or prepend the lines without colon (those are the lines with server1, server2 values) to the lines that follow those values (the lines with colon)
so that my output will look something like this ....

SERVER1:AAAA:11111:BLAH BLAH:BLAH
SERVER1:bbbb:11111:BLAH BLAH:BLAH
#--------------------------------#
SERVER2:STUFF:STUFF2:11111:TEST
#--------------------------------#


How do I go about doing this ?

Any help would be greatly appreciated.

Thanks,
Shabu
3 REPLIES 3
Stuart Browne
Honored Contributor
Solution

Re: script help

There'll undoutably be good perl solutions soon, but here's a quick 'awk' solution:

awk -F':' '/^#/ { print } { if (NF == 1) { HEADER=$1; next;} ; printf( "%s:%s\n", HEADER, $0 ); }' < InputFile
One long-haired git at your service...
Shabu Khan_1
Advisor

Re: script help

Thanks Stuart !

That was pretty neat ...

-Shabu
Fred Ruffet
Honored Contributor

Re: script help

a perl version...

$file="open(file);
while() {
chomp;
~ m/:/g;
if (pos) { print "$header:$_\n"; }
else { $header=$_; }
}
close(file);
--

"Reality is just a point of view." (P. K. D.)