Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Newbie question: most efficient way to search fields of this file

Reply
Thread Tools

Newbie question: most efficient way to search fields of this file

 
 
martin
Guest
Posts: n/a
 
      04-14-2006
Hi, I am quite new to perl and need to filter/process a file and print
into another file the processed file's results. I have .csv file that
is created by a perl script. The fomat of the file is
'M' lines or rows, and 'N' columns. the first row and the first column
are headers or labels.
all the fields are comma separated and are numeric values with the
excpetion of header and row columns shown below which are string
values, or labels.

Also the number of rows and columns could be as large as 1000 each.


I need to extract for a given column, example col4hdr, the
corresponding value for some of the rows and then print them in a
different file.


col1label, col2label, col3label, col4label, ..., colNlabel
row1hdr, int1, int2, ..., ... , intN-1
row2hdr, ... , ....,
.... ,... , ... , ... , ...., ...
rowMhdr ...., ..., ... , ..., ....

for example: if I were to extract and display the results for column4
and rows 2, 5, and 10, the output should like something like this

col1label col4label
row2hdr field value for 2,4
row5hdr field value for 5,4
row10hdr field value for 10,4

What is the most efficient way to do this, is there a built in
function in perl that does it,
how can I perl script this? should I turn the file into an array line
by line, or simply grep the file line by line for patterns maching
rows2hdr, row5hdr, row10hdr and then count 4 fileds till I extract the
corresponding value and store it for display.

and also is it best to use perl or unix shell scripting for this. any
input appreciated.

thanks. martin

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-14-2006
"martin" <(E-Mail Removed)> wrote:
> Hi, I am quite new to perl and need to filter/process a file and print
> into another file the processed file's results. I have .csv file that
> is created by a perl script. The fomat of the file is
> 'M' lines or rows, and 'N' columns. the first row and the first column
> are headers or labels.
> all the fields are comma separated and are numeric values with the
> excpetion of header and row columns shown below which are string
> values, or labels.
>
> Also the number of rows and columns could be as large as 1000 each.
>
> I need to extract for a given column, example col4hdr, the
> corresponding value for some of the rows and then print them in a
> different file.
>
> col1label, col2label, col3label, col4label, ..., colNlabel
> row1hdr, int1, int2, ..., ... , intN-1
> row2hdr, ... , ....,
> ... ,... , ... , ... , ...., ...
> rowMhdr ...., ..., ... , ..., ....
>
> for example: if I were to extract and display the results for column4
> and rows 2, 5, and 10, the output should like something like this
>
> col1label col4label
> row2hdr field value for 2,4
> row5hdr field value for 5,4
> row10hdr field value for 10,4


Do you recognize row 2 because the label is row2hdr, or because it is
2nd line after the header?

> What is the most efficient way to do this,


Efficient in your time? (depends on how good you are in every possible
language). Efficient on the computer's time? Probably assembly language.


> is there a built in
> function in perl that does it,


No, not directly.

> how can I perl script this? should I turn the file into an array line
> by line,


No. There is no reason to slurp it (if that is what you meant), although
it probably wouldn't hurt much for 1000 lines of 1000 numbers. And
certainly no reason to split every line, including the ones you don't care
about, if that is what you meant.

> or simply grep the file line by line for patterns maching
> rows2hdr, row5hdr, row10hdr and then count 4 fileds till I extract the
> corresponding value and store it for display.


Something like that, sure.

Assuming the list of rows is in order, something like this:

my $col=4;
my @rowlist=(2,5,10)
$col--; # convert to 0-started array
foreach my $line (@rowlist) {
defined ($_=<$fh>) or die until /^row${line}hdr,/;
chomp;
print "row${line}hdr,", (split/,/)[$col], "\n"
};


> and also is it best to use perl or unix shell scripting for this. any
> input appreciated.


As someone who doesn't remember how to shell script anything more
interesting than a loop, I'd have to say that, for me at least, Perl is
better than shell scripting for this.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
Charles DeRykus
Guest
Posts: n/a
 
      04-14-2006
martin wrote:
> Hi, I am quite new to perl and need to filter/process a file and print
> into another file the processed file's results. I have .csv file that
> is created by a perl script. The fomat of the file is
> 'M' lines or rows, and 'N' columns. the first row and the first column
> are headers or labels.
> all the fields are comma separated and are numeric values with the
> excpetion of header and row columns shown below which are string
> values, or labels.
>
> Also the number of rows and columns could be as large as 1000 each.
>
>
> I need to extract for a given column, example col4hdr, the
> corresponding value for some of the rows and then print them in a
> different file.
>
>
> col1label, col2label, col3label, col4label, ..., colNlabel
> row1hdr, int1, int2, ..., ... , intN-1
> row2hdr, ... , ....,
> ... ,... , ... , ... , ...., ...
> rowMhdr ...., ..., ... , ..., ....
>
> for example: if I were to extract and display the results for column4
> and rows 2, 5, and 10, the output should like something like this
>
> col1label col4label
> row2hdr field value for 2,4
> row5hdr field value for 5,4
> row10hdr field value for 10,4
>
> What is the most efficient way to do this, is there a built in
> function in perl that does it,
> how can I perl script this? should I turn the file into an array line
> by line, or simply grep the file line by line for patterns maching
> rows2hdr, row5hdr, row10hdr and then count 4 fileds till I extract the
> corresponding value and store it for display.
>
> and also is it best to use perl or unix shell scripting for this. any
> input appreciated.


I wouldn't go to shell-hell for this...

A new module File::Tablular has lots of functionality for this if
you anticipate more complexity ... or maybe DBD::CSV.

Or, if you need only simple operations Tie::File might help in
framing a data structure that you could expand by splitting the
lines.

Or, if you can't be bothered with all that... something like
this might work:

perl -F, -lane 'push( @{$line[$i++]}, @F );
END{ print @{line[$_]}[0,3] for (0, 1, 4, 9) }' csv_file > out


hth,
--
Charles DeRykus
 
Reply With Quote
 
martin
Guest
Posts: n/a
 
      04-14-2006
Thanks, I should have clarified one point. with respect to your
question

" Do you recognize row 2 because the label is row2hdr, or because it is
> 2nd line after the header?"


I used 'row2hdr' simplay as a label, so number 2 there or any other
digit is not the point. The row and column labels are strings, and for
that matter could have been "apple", "orange", "tomato". so what needs
to be done is to reference entries through string labels, without
numerical characters. I don't want to use number in rows and strings
because the position of rows could change; and prefer to index entries
through matching row labels and column labels.

and by efficiency I meant a combination of both, leaning towards time
of execution. of course I was not referring to assembly though.

tx

martin

> > Hi, I am quite new to perl and need to filter/process a file and print
> > into another file the processed file's results. I have .csv file that
> > is created by a perl script. The fomat of the file is
> > 'M' lines or rows, and 'N' columns. the first row and the first column
> > are headers or labels.
> > all the fields are comma separated and are numeric values with the
> > excpetion of header and row columns shown below which are string
> > values, or labels.
> >
> > Also the number of rows and columns could be as large as 1000 each.
> >
> > I need to extract for a given column, example col4hdr, the
> > corresponding value for some of the rows and then print them in a
> > different file.
> >
> > col1label, col2label, col3label, col4label, ..., colNlabel
> > row1hdr, int1, int2, ..., ... , intN-1
> > row2hdr, ... , ....,
> > ... ,... , ... , ... , ...., ...
> > rowMhdr ...., ..., ... , ..., ....
> >
> > for example: if I were to extract and display the results for column4
> > and rows 2, 5, and 10, the output should like something like this
> >
> > col1label col4label
> > row2hdr field value for 2,4
> > row5hdr field value for 5,4
> > row10hdr field value for 10,4

>
> Do you recognize row 2 because the label is row2hdr, or because it is
> 2nd line after the header?
>
> > Hi, I am quite new to perl and need to filter/process a file and print
> > into another file the processed file's results. I have .csv file that
> > is created by a perl script. The fomat of the file is
> > 'M' lines or rows, and 'N' columns. the first row and the first column
> > are headers or labels.
> > all the fields are comma separated and are numeric values with the
> > excpetion of header and row columns shown below which are string
> > values, or labels.
> >
> > Also the number of rows and columns could be as large as 1000 each.
> >
> > I need to extract for a given column, example col4hdr, the
> > corresponding value for some of the rows and then print them in a
> > different file.
> >
> > col1label, col2label, col3label, col4label, ..., colNlabel
> > row1hdr, int1, int2, ..., ... , intN-1
> > row2hdr, ... , ....,
> > ... ,... , ... , ... , ...., ...
> > rowMhdr ...., ..., ... , ..., ....
> >
> > for example: if I were to extract and display the results for column4
> > and rows 2, 5, and 10, the output should like something like this
> >
> > col1label col4label
> > row2hdr field value for 2,4
> > row5hdr field value for 5,4
> > row10hdr field value for 10,4

>
> Do you recognize row 2 because the label is row2hdr, or because it is
> 2nd line after the header?
>

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> "martin" <(E-Mail Removed)> wrote:


> > Hi, I am quite new to perl and need to filter/process a file and print
> > into another file the processed file's results. I have .csv file that
> > is created by a perl script. The fomat of the file is
> > 'M' lines or rows, and 'N' columns. the first row and the first column
> > are headers or labels.
> > all the fields are comma separated and are numeric values with the
> > excpetion of header and row columns shown below which are string
> > values, or labels.
> >
> > Also the number of rows and columns could be as large as 1000 each.
> >
> > I need to extract for a given column, example col4hdr, the
> > corresponding value for some of the rows and then print them in a
> > different file.
> >
> > col1label, col2label, col3label, col4label, ..., colNlabel
> > row1hdr, int1, int2, ..., ... , intN-1
> > row2hdr, ... , ....,
> > ... ,... , ... , ... , ...., ...
> > rowMhdr ...., ..., ... , ..., ....
> >
> > for example: if I were to extract and display the results for column4
> > and rows 2, 5, and 10, the output should like something like this
> >
> > col1label col4label
> > row2hdr field value for 2,4
> > row5hdr field value for 5,4
> > row10hdr field value for 10,4

>
> Do you recognize row 2 because the label is row2hdr, or because it is
> 2nd line after the header?
>
> > What is the most efficient way to do this,

>
> Efficient in your time? (depends on how good you are in every possible
> language). Efficient on the computer's time? Probably assembly language.
>
>
> > is there a built in
> > function in perl that does it,

>
> No, not directly.
>
> > how can I perl script this? should I turn the file into an array line
> > by line,

>
> No. There is no reason to slurp it (if that is what you meant), although
> it probably wouldn't hurt much for 1000 lines of 1000 numbers. And
> certainly no reason to split every line, including the ones you don't care
> about, if that is what you meant.
>
> > or simply grep the file line by line for patterns maching
> > rows2hdr, row5hdr, row10hdr and then count 4 fileds till I extract the
> > corresponding value and store it for display.

>
> Something like that, sure.
>
> Assuming the list of rows is in order, something like this:
>
> my $col=4;
> my @rowlist=(2,5,10)
> $col--; # convert to 0-started array
> foreach my $line (@rowlist) {
> defined ($_=<$fh>) or die until /^row${line}hdr,/;
> chomp;
> print "row${line}hdr,", (split/,/)[$col], "\n"
> };
>
>
> > and also is it best to use perl or unix shell scripting for this. any
> > input appreciated.

>
> As someone who doesn't remember how to shell script anything more
> interesting than a loop, I'd have to say that, for me at least, Perl is
> better than shell scripting for this.
>
> Xho
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB


 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-14-2006
martin wrote:
> Hi, I am quite new to perl and need to filter/process a file and print
> into another file the processed file's results.


<snip>

> What is the most efficient way to do this,


Which ways have you considered? You can always use the Benchmark module
to compare them...

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Xicheng Jia
Guest
Posts: n/a
 
      04-14-2006
martin wrote:
> Hi, I am quite new to perl and need to filter/process a file and print
> into another file the processed file's results. I have .csv file that
> is created by a perl script. The fomat of the file is
> 'M' lines or rows, and 'N' columns. the first row and the first column
> are headers or labels.
> all the fields are comma separated and are numeric values with the
> excpetion of header and row columns shown below which are string
> values, or labels.
>
> Also the number of rows and columns could be as large as 1000 each.
>
>
> I need to extract for a given column, example col4hdr, the
> corresponding value for some of the rows and then print them in a
> different file.
>
>
> col1label, col2label, col3label, col4label, ..., colNlabel
> row1hdr, int1, int2, ..., ... , intN-1
> row2hdr, ... , ....,
> ... ,... , ... , ... , ...., ...
> rowMhdr ...., ..., ... , ..., ....
>
> for example: if I were to extract and display the results for column4
> and rows 2, 5, and 10, the output should like something like this
>
> col1label col4label
> row2hdr field value for 2,4
> row5hdr field value for 5,4
> row10hdr field value for 10,4
>
> What is the most efficient way to do this, is there a built in
> function in perl that does it,
> how can I perl script this? should I turn the file into an array line
> by line, or simply grep the file line by line for patterns maching
> rows2hdr, row5hdr, row10hdr and then count 4 fileds till I extract the
> corresponding value and store it for display.


== and also is it best to use perl or unix shell scripting for this.
any
== input appreciated.>

You should handle this by line-mode and it can be easily done on the
command line. I dont think perl will be better than awk though:

perl -F, -anle 'print join"\t", @F[0,3] if $. =~ /^(1|2|5|10)$/'
myfile.csv

awk -F, 'NR ~ /^(1|2|5|10)$/ {print $1,$3}' myfile.csv

Xicheng

 
Reply With Quote
 
Xicheng Jia
Guest
Posts: n/a
 
      04-14-2006
Xicheng Jia wrote:
> martin wrote:
> > Hi, I am quite new to perl and need to filter/process a file and print
> > into another file the processed file's results. I have .csv file that
> > is created by a perl script. The fomat of the file is
> > 'M' lines or rows, and 'N' columns. the first row and the first column
> > are headers or labels.
> > all the fields are comma separated and are numeric values with the
> > excpetion of header and row columns shown below which are string
> > values, or labels.
> >
> > Also the number of rows and columns could be as large as 1000 each.
> >
> >
> > I need to extract for a given column, example col4hdr, the
> > corresponding value for some of the rows and then print them in a
> > different file.
> >
> >
> > col1label, col2label, col3label, col4label, ..., colNlabel
> > row1hdr, int1, int2, ..., ... , intN-1
> > row2hdr, ... , ....,
> > ... ,... , ... , ... , ...., ...
> > rowMhdr ...., ..., ... , ..., ....
> >
> > for example: if I were to extract and display the results for column4
> > and rows 2, 5, and 10, the output should like something like this
> >
> > col1label col4label
> > row2hdr field value for 2,4
> > row5hdr field value for 5,4
> > row10hdr field value for 10,4
> >
> > What is the most efficient way to do this, is there a built in
> > function in perl that does it,
> > how can I perl script this? should I turn the file into an array line
> > by line, or simply grep the file line by line for patterns maching
> > rows2hdr, row5hdr, row10hdr and then count 4 fileds till I extract the
> > corresponding value and store it for display.

>
> == and also is it best to use perl or unix shell scripting for this.
> any
> == input appreciated.>
>
> You should handle this by line-mode and it can be easily done on the
> command line. I dont think perl will be better than awk though:
>
> perl -F, -anle 'print join"\t", @F[0,3] if $. =~ /^(1|2|5|10)$/'
> myfile.csv
>

= awk -F, 'NR ~ /^(1|2|5|10)$/ {print $1,$3}' myfile.csv

~~change to $4

In fact, if regex is a consideration factor, 'awk' may be better than
'perl', since awk is using DFA regex engine which is faster than perl's
NFA.

Xicheng

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      04-14-2006
martin <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Thanks, I should have clarified one point. with respect to your
> question
>
> " Do you recognize row 2 because the label is row2hdr, or because it is
> > 2nd line after the header?"

>
> I used 'row2hdr' simplay as a label, so number 2 there or any other
> digit is not the point. The row and column labels are strings, and for
> that matter could have been "apple", "orange", "tomato". so what needs
> to be done is to reference entries through string labels, without
> numerical characters. I don't want to use number in rows and strings
> because the position of rows could change; and prefer to index entries
> through matching row labels and column labels.
>
> and by efficiency I meant a combination of both, leaning towards time
> of execution. of course I was not referring to assembly though.


You have essentially two problems then (which is good, it's called
problem separation). One is to select the lines to process, the other
is to select from those lines the columns requested.

Assume the requirements in two variables, for instance:

my @lines = qw( row2hdr rowMhdr);
my @cols = qw( col1label colNlabel col2label);

We want to select all lines that begin with one of the given headers.
That is a job for a regular expression, so let's compile one:

my $line_re = do {
my $re = join '|', sort { length( $b) <=> length( $a) } @lines;
qr/^$re/;
};

We sort long alternatives ahead of short ones in case one is a prefix
of another. Now $line_re will match the lines that interest us and no
others.

Column selection cannot be done using strings alone, because the header
strings are nowhere around when we look at a data line. Instead, we
translate the set of column headers into a set of integer indices that
point to the columns we want. For the translation we use the first line
of the data file, containing the actual headers for this set of data:

my @sel = do {
chomp( my $h_line = <DATA>);
my @headers = split /\s*,\s*/, $h_line;
my %col_of_header = map { shift( @headers) => $_ } 0 .. $#headers;
my @bad = grep !defined $col_of_header{ $_}, @cols;
die "bad header(s): @bad" if @bad;
@col_of_header{ @cols};
};

Now we're ready to print the header line and the selected data:

print join( ', ', @cols), "\n";
while ( <DATA> ) {
next unless /$line_re/;
my @recs = split /\s*,\s*/;
print join( ', ', @recs[ @sel]), "\n";
}

__DATA__
col1label, col2label, col3label, col4label, ..., colNlabel
row1hdr, int1, int2, ..., ... , intN-1
row2hdr, ... , ...., xxxx, ...., yyyy, zzzz
... ,... , ... , ... , ...., ...
rowMhdr, ...., ..., ... , ..., ...., corner

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
martin
Guest
Posts: n/a
 
      04-15-2006
Hi everyone, thanks for all the valuable input. I need to read a bit to
digest. The last reply brought another question, that I will read a bit
on before doing a posting. Thanks again. Martin

 
Reply With Quote
 
Xicheng Jia
Guest
Posts: n/a
 
      04-15-2006
martin wrote:
> Thanks, I should have clarified one point. with respect to your
> question
>
> " Do you recognize row 2 because the label is row2hdr, or because it is
> > 2nd line after the header?"

>

=> I used 'row2hdr' simplay as a label, so number 2 there or any other
=> digit is not the point. The row and column labels are strings, and
for
=> that matter could have been "apple", "orange", "tomato". so what
needs
=> to be done is to reference entries through string labels, without
=> numerical characters. I don't want to use number in rows and strings
=> because the position of rows could change; and prefer to index
entries
=> through matching row labels and column labels.

this kind of text searching can be done in Perl like:

perl -ne ' @x = split/\s*,\s*/;
print join ",", @x[0, 3] if $.==1 || /^(row1hdr|row2hdr)/'
myfile.csv

or in awk:

awk -F' *, *' 'NR==1 || $1 ~ /^(row1hdr|row2hdr)/ {print $1,$4}'
myfile.csv

( awk's -F option on the command-line is more powerful than perl's )

Xicheng

> and by efficiency I meant a combination of both, leaning towards time
> of execution. of course I was not referring to assembly though.
>
> tx
>
> martin
>
> > > Hi, I am quite new to perl and need to filter/process a file and print
> > > into another file the processed file's results. I have .csv file that
> > > is created by a perl script. The fomat of the file is
> > > 'M' lines or rows, and 'N' columns. the first row and the first column
> > > are headers or labels.
> > > all the fields are comma separated and are numeric values with the
> > > excpetion of header and row columns shown below which are string
> > > values, or labels.
> > >
> > > Also the number of rows and columns could be as large as 1000 each.
> > >
> > > I need to extract for a given column, example col4hdr, the
> > > corresponding value for some of the rows and then print them in a
> > > different file.
> > >
> > > col1label, col2label, col3label, col4label, ..., colNlabel
> > > row1hdr, int1, int2, ..., ... , intN-1
> > > row2hdr, ... , ....,
> > > ... ,... , ... , ... , ...., ...
> > > rowMhdr ...., ..., ... , ..., ....
> > >
> > > for example: if I were to extract and display the results for column4
> > > and rows 2, 5, and 10, the output should like something like this
> > >
> > > col1label col4label
> > > row2hdr field value for 2,4
> > > row5hdr field value for 5,4
> > > row10hdr field value for 10,4

> >
> > Do you recognize row 2 because the label is row2hdr, or because it is
> > 2nd line after the header?
> >
> > > Hi, I am quite new to perl and need to filter/process a file and print
> > > into another file the processed file's results. I have .csv file that
> > > is created by a perl script. The fomat of the file is
> > > 'M' lines or rows, and 'N' columns. the first row and the first column
> > > are headers or labels.
> > > all the fields are comma separated and are numeric values with the
> > > excpetion of header and row columns shown below which are string
> > > values, or labels.
> > >
> > > Also the number of rows and columns could be as large as 1000 each.
> > >
> > > I need to extract for a given column, example col4hdr, the
> > > corresponding value for some of the rows and then print them in a
> > > different file.
> > >
> > > col1label, col2label, col3label, col4label, ..., colNlabel
> > > row1hdr, int1, int2, ..., ... , intN-1
> > > row2hdr, ... , ....,
> > > ... ,... , ... , ... , ...., ...
> > > rowMhdr ...., ..., ... , ..., ....
> > >
> > > for example: if I were to extract and display the results for column4
> > > and rows 2, 5, and 10, the output should like something like this
> > >
> > > col1label col4label
> > > row2hdr field value for 2,4
> > > row5hdr field value for 5,4
> > > row10hdr field value for 10,4

> >
> > Do you recognize row 2 because the label is row2hdr, or because it is
> > 2nd line after the header?
> >

> (E-Mail Removed) wrote:
> > "martin" <(E-Mail Removed)> wrote:

>
> > > Hi, I am quite new to perl and need to filter/process a file and print
> > > into another file the processed file's results. I have .csv file that
> > > is created by a perl script. The fomat of the file is
> > > 'M' lines or rows, and 'N' columns. the first row and the first column
> > > are headers or labels.
> > > all the fields are comma separated and are numeric values with the
> > > excpetion of header and row columns shown below which are string
> > > values, or labels.
> > >
> > > Also the number of rows and columns could be as large as 1000 each.
> > >
> > > I need to extract for a given column, example col4hdr, the
> > > corresponding value for some of the rows and then print them in a
> > > different file.
> > >
> > > col1label, col2label, col3label, col4label, ..., colNlabel
> > > row1hdr, int1, int2, ..., ... , intN-1
> > > row2hdr, ... , ....,
> > > ... ,... , ... , ... , ...., ...
> > > rowMhdr ...., ..., ... , ..., ....
> > >
> > > for example: if I were to extract and display the results for column4
> > > and rows 2, 5, and 10, the output should like something like this
> > >
> > > col1label col4label
> > > row2hdr field value for 2,4
> > > row5hdr field value for 5,4
> > > row10hdr field value for 10,4

> >
> > Do you recognize row 2 because the label is row2hdr, or because it is
> > 2nd line after the header?
> >
> > > What is the most efficient way to do this,

> >
> > Efficient in your time? (depends on how good you are in every possible
> > language). Efficient on the computer's time? Probably assembly language.
> >
> >
> > > is there a built in
> > > function in perl that does it,

> >
> > No, not directly.
> >
> > > how can I perl script this? should I turn the file into an array line
> > > by line,

> >
> > No. There is no reason to slurp it (if that is what you meant), although
> > it probably wouldn't hurt much for 1000 lines of 1000 numbers. And
> > certainly no reason to split every line, including the ones you don't care
> > about, if that is what you meant.
> >
> > > or simply grep the file line by line for patterns maching
> > > rows2hdr, row5hdr, row10hdr and then count 4 fileds till I extract the
> > > corresponding value and store it for display.

> >
> > Something like that, sure.
> >
> > Assuming the list of rows is in order, something like this:
> >
> > my $col=4;
> > my @rowlist=(2,5,10)
> > $col--; # convert to 0-started array
> > foreach my $line (@rowlist) {
> > defined ($_=<$fh>) or die until /^row${line}hdr,/;
> > chomp;
> > print "row${line}hdr,", (split/,/)[$col], "\n"
> > };
> >
> >
> > > and also is it best to use perl or unix shell scripting for this. any
> > > input appreciated.

> >
> > As someone who doesn't remember how to shell script anything more
> > interesting than a loop, I'd have to say that, for me at least, Perl is
> > better than shell scripting for this.
> >
> > Xho
> >
> > --
> > -------------------- http://NewsReader.Com/ --------------------
> > Usenet Newsgroup Service $9.95/Month 30GB


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Most efficient way to transfer a file directory recursively (using sockets) Arash Nikkar Java 8 11-27-2006 10:21 PM
Most Efficient Way of Exporting CSV data from page Peter ASP .Net 1 11-09-2004 10:41 PM
The most efficient way to innitialize an array with an innitialization list Razvan Java 11 10-11-2004 11:08 PM
What is the most efficient way to access common fcts on asp.net pages when using user controls? Brent Minder ASP .Net 3 12-28-2003 02:28 PM
most efficient way to get a connection from a connection pool Linus Nikander Java 5 09-18-2003 04:34 AM



Advertisments