Ask a Question related to PERL Beginners, Design and Development.
-
John W. Krahn #1
Re: Data File, turn fields on mulitple lines into records on one li ne.. .
Taylor Lewick wrote:
open my $in, '<', 'file1' or die "Cannot open file1: $!";>
> From: John W. Krahn [mailto:krahnj@acm.org]>> >
> > Taylor Lewick wrote:> >> > >
> > > Okay, I redid it so it looks like this...
> > >
> > > `grep -v "STUFF:STUFF" file1 > file2`;
> > Is that what the ACTUAL line looks like?
> >> >> > > (I am looking for the string
> > > STUFF:STUFF and that didn't work... but it works via command line...
> > >
> > > Any ideas?
> > Use perl to do it:
> >
> > open my $in, '<', 'file1' or die "Cannot open file1: $!";
> > open my $out, '>', 'file2' or die "Cannot open file2: $!";
> > while ( <$in> ) {
> > next if /STUFF:STUFF/;
> > print $out;
> > }
> > close $out;
> > close $in;
> Okay, will do... One more, what about a sed command that deletes the
> first 3 spaces of each line... i.e., how would I do this in perl...
>
> sed 's/^ //' file1 > file2
open my $out, '>', 'file2' or die "Cannot open file2: $!";
while ( <$in> ) {
s/^ //;
print $out;
}
close $out;
close $in;
John
--
use Perl;
program
fulfillment
John W. Krahn Guest
-
Data File, turn fields on mulitple lines into records on one line.. .
Taylor Lewick wrote: are entries always separate by an empty line? you don't need to load everything into an array or hash. you can read... -
Data File, turn fields on mulitple lines into records on one li ne.. .
Please bottom post... John just provided a good one. Optionally if all you care about is determining whether a line contains a string it might... -
Data File, turn fields on mulitple lines into records on one li ne.. .
Taylor Lewick wrote: Is that what the ACTUAL line looks like? Use perl to do it: open my $in, '<', 'file1' or die "Cannot open file1:... -
Data File, turn fields on mulitple lines into records on one li ne.. .
What is the "real" goal? Aka why are you shelling out to grep in the first place? As a side note you should be using full paths for grep, file1,... -
Data File, turn fields on mulitple lines into records on one li ne.. .
Taylor Lewick wrote: Yes, you have the file name in the wrong place. The syntax is "do something to FILE | pipe data to second process | pipe...



Reply With Quote

