Xref: utzoo comp.unix.questions:18451 comp.unix.wizards:19776 comp.sources.wanted:9788 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!convex!tchrist@convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions,comp.unix.wizards,comp.sources.wanted Subject: Re: Datafile conversion with AWK ! Summary: i didn't really use awk :-) Keywords: datafile conversion awk sed Message-ID: <3946@convex.UUCP> Date: 14 Dec 89 11:25:34 GMT References: <539@csoftec.csf.com> Sender: news@convex.UUCP Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 33 In article <539@csoftec.csf.com> root@csoftec.csf.com (Cliff Manis (cmanis@csoftec)) writes: >I am needing help with data conversion, and would appreciate help >in AWK or SED and/or awk & sed. Or whatever.... If you'll accept perl (version 3.0 because I like the array slices), this code does it for you, assuming the input files are really as shown: #!/usr/bin/perl while (<>) { chop; split(/\|/); if ( $_[$#_] == 1 ) { &print_line unless $#addrs < 0; @preamble = @_[0..2]; @addrs = @_[3]; @postamble = @_[4..$#_]; } else { push(@addrs, $_[3]); } } &print_line; sub print_line { push(@addrs,'') while $#addrs < 3; print join ('|', @preamble, @addrs, @postamble), "\n"; } I thought it a bit odd that the input data had a trailing pipe and the requested output data didn't, but that's what the guy wanted. If he really does want a trailing pipe, change the last print line to: print join ('|', @preamble, @addrs, @postamble, "\n"); Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "EMACS belongs in : Editor too big!"