[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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@pm.org [mailto:omaha-pm-bounces@pm.org] On Behalf
Of Jay Hannah
Sent: Monday, December 19, 2005 6:34 PM
To: omaha-pm@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@pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm