Re: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread John W. Krahn
Taylor Lewick wrote:
> 
> From: John W. Krahn [mailto:[EMAIL PROTECTED]
> > 
> > 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 $in,  '<', 'file1' or die "Cannot open file1: $!";
open my $out, '>', 'file2' or die "Cannot open file2: $!";
while ( <$in> ) {
s/^   //;
print $out;
}
close $out;
close $in;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread Wiggins d Anconia
Please bottom post...

> So you recommend using regular expressions instead of grep..?
> Care to provide an example in this case?
> 

John just provided a good one. Optionally if all you care about is
determining whether a line contains a string it might (I didn't
benchmark it) be faster to use 'index' instead of a regex:

perldoc -f index

My complaint is about the use of shelling out to handle something that
can be easily done programmatically within Perl itself, aka like John
showed using two opens and a simple while with the diamond operator (and
conveniently it has more error checking in it, should be faster, is more
secure, less error prone, and portable!).  To me shelling out is a last
resort, or a quick fix (aka if you have to ask here it isn't quick enough).

http://danconia.org

> -Original Message-
> From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] 
> Sent: Friday, January 16, 2004 3:16 PM
> To: Lewick, Taylor; [EMAIL PROTECTED]
> Subject: RE: Data File, turn fields on mulitple lines into records on
> one li ne.. .
> 
> 
> 
> > Okay, I redid it so it looks like this...
> > 
> > `grep -v "STUFF:STUFF" file1 > file2`;  (I am looking for the string
> > STUFF:STUFF and that didn't work...  but it works via command line...
> > 
> > Any ideas?
> 
> 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, file2, and you should be checking the return code of the command.
> Also it seems silly to use backticks if you are piping STDOUT to a file.
> 
> http://danconia.org
> 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread Lewick, Taylor
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

-Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 16, 2004 3:24 PM
To: [EMAIL PROTECTED]
Subject: Re: Data File, turn fields on mulitple lines into records on
one li ne.. .

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;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread Lewick, Taylor
So you recommend using regular expressions instead of grep..?
Care to provide an example in this case?

-Original Message-
From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 16, 2004 3:16 PM
To: Lewick, Taylor; [EMAIL PROTECTED]
Subject: RE: Data File, turn fields on mulitple lines into records on
one li ne.. .



> Okay, I redid it so it looks like this...
> 
> `grep -v "STUFF:STUFF" file1 > file2`;  (I am looking for the string
> STUFF:STUFF and that didn't work...  but it works via command line...
> 
> Any ideas?

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, file2, and you should be checking the return code of the command.
Also it seems silly to use backticks if you are piping STDOUT to a file.

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread John W. Krahn
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;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread Wiggins d Anconia


> Okay, I redid it so it looks like this...
> 
> `grep -v "STUFF:STUFF" file1 > file2`;  (I am looking for the string
> STUFF:STUFF and that didn't work...  but it works via command line...
> 
> Any ideas?

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, file2, and you should be checking the return code of the command.
Also it seems silly to use backticks if you are piping STDOUT to a file.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread Lewick, Taylor
Okay, I redid it so it looks like this...

`grep -v "STUFF:STUFF" file1 > file2`;  (I am looking for the string
STUFF:STUFF and that didn't work...  but it works via command line...

Any ideas?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread John W. Krahn
Taylor Lewick wrote:
> 
> One more for everyone...
> In my perl script, I did a quick cheat by using the systems grep
> command...
> I tried:
> `/usr/bin/grep -v "BLAH" | /usr/bin/grep -v "COW" | /usr/bin/grep -v
> "STUFF" file1>file2`;
> 
> And this doesn't work.  Sometimes it will get rid of STUFF.  It seems to
> only act on the last grep I use.  I tried escaping the pipes, but that
> didn't work.  Any ideas?

Yes, you have the file name in the wrong place.  The syntax is "do
something to FILE | pipe data to second process | pipe data to third
process > redirect STDOUT to a file".  What you have is "do something to
STDIN | pipe data to second process | pipe data to third process but use
FILE instead > redirect STDOUT to a file".  You have to specify the file
name on the first process in the pipeline.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Data File, turn fields on mulitple lines into records on one li ne.. .

2004-01-16 Thread Lewick, Taylor
Thanks Ron, will give that a try..

One more for everyone...
In my perl script, I did a quick cheat by using the systems grep
command...
I tried:
`/usr/bin/grep -v "BLAH" | /usr/bin/grep -v "COW" | /usr/bin/grep -v
"STUFF" file1>file2`;

And this doesn't work.  Sometimes it will get rid of STUFF.  It seems to
only act on the last grep I use.  I tried escaping the pipes, but that
didn't work.  Any ideas?

Thanks...


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]