Datafile conversion with AWK !

Rock Kent rock at rancho.uucp
Thu Dec 14 19:19:17 AEST 1989


<note I have deleted comp.unix.wizards . . . I'm sure they already know this.>

On 13 Dec 89 23:53:07 GMT, Cliff Manis(cmanis at csoftec) said:

Cliff> I am needing help with data conversion, and would appreciate help 
Cliff> in AWK or SED and/or awk & sed.  
           [to convert from]
Cliff> AA1|name1|4you|ABC Co|3|56|a|bbb|c|d|eeee|fff|g|1|
Cliff> AA1|name1|4you|5th ST||||||||||2|
Cliff> AA1|name1|4you|Go4it, TX||||||||||3|
           [to]
Cliff> AA1|name1|4you|ABC Co|5th ST|Go4it, TX||3|56|a|bbb|c|d|eeee|fff|g|1

Try:   awk -f reform.awk inputfile 
where reform.awk is as follows:
---------snip-snip-snip-snip---------------------------------------------------
BEGIN{FS="|"}
{
if (prior != $1 $2 $3) {
  if (prior != ""){ 
    for (j=1;j<17;j++) {printf "%s|", line[j]};
    printf "%s\n", line[17]; };
  prior = $1 $2 $3;
  split($0,line,"|");
  for (i=17;i>7;i--){line[i]=line[i-3]};
  for (i=5;i<8;i++){line[i]=""};
  l=4}
else {
  l=l+1;
  line[l]=$4;}
}
END{
for (j=1;j<17;j++) {printf "%s|", line[j]};
printf "%s\n", line[17];
}
---------snip-snip-snip-snip---------------------------------------------------

***************************************************************************
*Rock Kent    rock at rancho.uucp        POB 8964, Rancho Sante Fe, CA. 92067*
***************************************************************************



More information about the Comp.unix.questions mailing list