Rearranging text into a certain format

March 12, 2011 at 07:02:09
Specs: Windows Vista
Hi Experts,

Good day.

Can you help me creating a script in rearranging the input text file into certain format below:

INPUT

DPC: 1234
SLC: 1.7/9.7 %
SLC: 1.0/9.3 %
DPC: 5678
SLC: 1.5/9.3 %
SLC: 1.5/9.3 %
SLC: 1.4/9.3 %
SLC: 1.1/9.8 %
DPC: 9123
SLC: 11.57/9.37 %
SLC: 11.50/9.37 %
SLC: 11.41/9.38 %
DPC: 2143
SLC: 11.41/9.38 %
------END-------


OUTPUT

SLC: 1.7/9.7 % : 1234
SLC: 1.0/9.3 % : 1234
SLC: 1.5/9.3 % : 5678
SLC: 1.5/9.3 % : 5678
SLC: 1.4/9.3 % : 5678
SLC: 1.1/9.8 % : 5678
SLC: 11.57/9.37 % : 9123
SLC: 11.50/9.37 % : 9123
SLC: 11.41/9.38 % : 9123
SLC: 11.41/9.38 % : 2143

Would it be doable in unix?


See More: Rearranging text into a certain format

Report •

#1
March 12, 2011 at 07:58:28
a way .....

#!/bin/ksh

awk ' {
if($1 ~ /^DPC:/)
   dpcvar=$2

if($1 ~ /^SLC:/)
   printf("%s : %s\n", $0, dpcvar)

}' datafile.txt


Report •

#2
March 13, 2011 at 03:37:32
Hi Nails,

Thank you very much for the script. It works perfectly and really saves time.

Regards,

Amiti


Report •
Related Solutions


Ask Question