[Omaha.pm] Add a pipe to a pipe delim file

Sean Baker pbaker at omnihotels.com
Tue Dec 20 07:13:25 PST 2005


If all you want to do is add a pipe to the end:

perl -pi -e "s/$/|/g" [filename]

Or the beginning:

perl -pi -e "s/^/|/g" [filename]


-----Original Message-----
From: omaha-pm-bounces at pm.org [mailto:omaha-pm-bounces at pm.org] On Behalf
Of Jay Hannah
Sent: Monday, December 19, 2005 6:34 PM
To: omaha-pm at pm.org
Subject: [Omaha.pm] Add a pipe to a pipe delim file


Problem:

You have a pipe delimited file and need to pretend that there's an extra
field right after the 9th field.

Solution:

$ cat j.pl
#!/usr/bin/perl

while (<>) {
  my @l = split /\|/;
  $l[8] = "$l[8]|";
  print join "|", @l;
}

I ran it like so:

$ perl j.pl reward_event_ar.unl > reward_event_ar.unl.2

I'm sure there's a shorter solution out there, but that's how I code
that solution off the top of my head.

j

_______________________________________________
Omaha-pm mailing list
Omaha-pm at pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm



More information about the Omaha-pm mailing list