From Robert.L.Harris at rdlg.net Sun Apr 1 04:33:44 2007 From: Robert.L.Harris at rdlg.net (Robert L. Harris) Date: Sun, 1 Apr 2007 07:33:44 -0400 Subject: [Boulder.pm] Perl Help In-Reply-To: References: <20070401013539.GI17856@rdlg.net> Message-ID: <20070401113344.GJ17856@rdlg.net> Completely understand. I've been there. If I can be of help feel free to ping me. Robert Thus spake Rod Burgess (rodbandkimb at msn.com): > Robert, > Thanks for providing this code. > I continue to learn new Perl tricks all of the time. > Again thanks. > Rod > > > >From: "Robert L. Harris" > >Reply-To: boulder-pm at pm.org > >To: boulder-pm at pm.org > >Subject: Re: [Boulder.pm] Perl Help > >Date: Sat, 31 Mar 2007 21:35:40 -0400 > > > > > > > > > >Being a little verbose. > > > >while() { > > chomp; > > ($Part, $Number, $Desc)=split(";",$_ine); > > if ($Part =~ /(.*)II/) { > > $NewPart=$1." II"; > > } elsif ( $Part =~ /(.*)([CDI])/) { > > $NewPart=$1." ".$2; > > } else { > > $NewPart=$Part; > > } > > print OUTPUT $NewPart.";".$Number.";".$Desc; > >} > > > > > > > > > > > >Thus spake Rod Burgess (rodbandkimb at msn.com): > > > > > I have the following file with three data fields separated by a "; > >semicol" > > > > > > 14567345;1;Oil Seal > > > 4533457C;1;Heat Shield > > > 56842204;1;Misc Part > > > 5481206D;1;Gasket > > > 81003589I;1;Washer > > > T23546II;1;Shirt > > > > > > The 1st Data Field is Part# > > > The 2nd Data Field is Number of Parts > > > The 3rd Data Field is Part Description > > > > > > The only change that I need to this file is if the 1st data field being > >the > > > part# ends in a "C,D,I, or II" > > > I would like the file to look like this (having a space between the part > > > number an its Identifier. > > > If that possible with Perl? Could someone show me a sample perl program > >to > > > do this? > > > > > > 14567345;1;Oil Seal > > > 4533457 C;1;Heat Shield > > > 56842204;1;Misc Part > > > 5481206 D;1;Gasket > > > 81003589 I;1;Washer > > > T23546 II;1;Shirt > > > > > > > > > _______________________________________________ > > > Boulder-pm mailing list > > > Boulder-pm at pm.org > > > http://mail.pm.org/mailman/listinfo/boulder-pm > > > >:wq! > >--------------------------------------------------------------------------- > >Robert L. Harris | GPG Key ID: E344DA3B > > @ x-hkp://pgp.mit.edu > >DISCLAIMER: > > These are MY OPINIONS With Dreams To Be A King, > > ALONE. I speak for First One Should Be A Man > > no-one else. - Manowar > > > > > ><< signature.asc >> > > > > > >_______________________________________________ > >Boulder-pm mailing list > >Boulder-pm at pm.org > >http://mail.pm.org/mailman/listinfo/boulder-pm > > > _______________________________________________ > Boulder-pm mailing list > Boulder-pm at pm.org > http://mail.pm.org/mailman/listinfo/boulder-pm :wq! --------------------------------------------------------------------------- Robert L. Harris | GPG Key ID: E344DA3B @ x-hkp://pgp.mit.edu DISCLAIMER: These are MY OPINIONS With Dreams To Be A King, ALONE. I speak for First One Should Be A Man no-one else. - Manowar -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://mail.pm.org/pipermail/boulder-pm/attachments/20070401/78b8895d/attachment.bin From yargevad at gmail.com Sun Apr 1 21:55:35 2007 From: yargevad at gmail.com (Dave Gray) Date: Sun, 1 Apr 2007 22:55:35 -0600 Subject: [Boulder.pm] Perl Help In-Reply-To: References: Message-ID: On 3/31/07, Rod Burgess wrote: > 14567345;1;Oil Seal > 4533457C;1;Heat Shield > 56842204;1;Misc Part > 5481206D;1;Gasket > 81003589I;1;Washer > T23546II;1;Shirt [becomes] > 14567345;1;Oil Seal > 4533457 C;1;Heat Shield > 56842204;1;Misc Part > 5481206 D;1;Gasket > 81003589 I;1;Washer > T23546 II;1;Shirt One-liners for fun and profit! perl -pi.bak -e 's/^(\d+)([CD]|I{1,2});/$1 $2;/' fileglob If you haven't done so, reading the 'perldoc perl' docs is enlightening. From nagler at bivio.biz Mon Apr 2 07:19:19 2007 From: nagler at bivio.biz (Rob Nagler) Date: Mon, 2 Apr 2007 08:19:19 -0600 Subject: [Boulder.pm] Perl Help In-Reply-To: References: Message-ID: <17937.4327.818268.396685@ski.local> Everybody else's solutions arew fine. However, this is the perl list and there's more than one way... I think the following might be clearer: perl -pe 's/(?=(?:C|D|I|II);)/ /' infile > outfile It demonstrates some of the more powerful regexp features which only perl seems to have. The regexp assertions (?=) are quite powerful. In this example, they allow me to list the different part # suffixes easily so a non-perl programmer could easily modify this program, I think. Rob PS. Also posted on pikes-peak-pm.