having issues using awk and/or converting to perl

D

Dr.Ruud

jthrumston:
Xicheng:
(e-mail address removed):
Basically all I am doing is pulling all records out of a file that
start with "F" and creating a new file of just those records.

you dont need to separate line into columns except that you need to
check contents in a specific column, like:

perl -anle 'print if $F[2] =~ /^F/' infile > outfile

this check if column-3 begins with 'F'...

This did exactly what I need (by changing the column to 0) from the
command line [...]
how do I incorporate that line inside a perl script? I have
11 files to do this exact operation on (though the column is not
always the same from report to report).

Now it is time for you to show us some code.

First check `perldoc perlrun` for what the "-anle" means.


A lean version without columns:

#!/usr/bin/perl

use warnings;
use strict;

while (<>) {
print if /^F/
}
 
G

Glenn Jackman

At 2006-01-09 10:47AM said:
Xicheng said:
Basically all I am doing is pulling all records out of a file that
start with "F" and creating a new file of just those records.
If this is what you want, just forget about using awk within perl
scripts, the perl onelier is easy as awk:

perl -nle 'print if /^F/' infile > outfile

you dont need to separate line into columns except that you need to
check contents in a specific column, like:

perl -anle 'print if $F[2] =~ /^F/' infile > outfile

this check if column-3 begins with 'F'...

This did exactly what I need (by changing the column to 0) from the
command line. I thank you Xicheng for suggesting that. My question now
would be, how do I incorporate that line inside a perl script? I have
11 files to do this exact operation on (though the column is not always
the same from report to report).

You could do something like this (untested), which will do a
line-oriented regexp search over a set of files:
my %search_conditions = (
file1 => qr{^F},
file2 => qr{suffix$},
...
);

foreach my $filename (keys %search_conditions) {
open my $f, '<', $filename or die "can't open '$filename': $!\n";
while (<$f>) {
# if match, output the filename, the line number and the line
print "$filename:$.:$_" if /$search_conditions{$filename}/;
}
close $f;
}
 
J

jthrumston

This thread went way out of whack. I apologize to all who were offended
by my lack of proper posting. I was only looking for some help and
wasn't aware of the rules (my fault).
To Paul, I am sorry for sounding off on you, I was taken quite by
surprise by my perception of an attack and I responded poorly.

I will not be posting here again, at least until I figure out how to do
it without fearing a flame response.

I do realize this is not a "board" I said the wrong thing.

I have found a solution to my original question. Thank you very much to
those who helped out.

Have a good day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top