Xref: utzoo comp.unix.questions:18425 comp.sources.wanted:9767 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucsd!ucsdhub!hp-sdd!ncr-sd!rancho!rock From: rock@rancho.uucp (Rock Kent) Newsgroups: comp.unix.questions,comp.sources.wanted Subject: Re: Datafile conversion with AWK ! Message-ID: <1989Dec14.081917.1363@rancho.uucp> Date: 14 Dec 89 08:19:17 GMT References: <539@csoftec.csf.com> Organization: Del Rayo Ranch, San Diego, CA Lines: 40 In-Reply-To: root@csoftec.csf.com's message of 13 Dec 89 23:53:07 GMT On 13 Dec 89 23:53:07 GMT, Cliff Manis(cmanis@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@rancho.uucp POB 8964, Rancho Sante Fe, CA. 92067* ***************************************************************************