Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading particular Column in text file

Newbie
 
Join Date: Dec 2006
Posts: 3
#1: Dec 4 '06
Hi friends,
I am facing problem in finding a code which should read particular column in text file.My code opens a file split it into an array & search the string but it search that in whole file while i want it to search in ap articular column because same string is in other columns.
My code is:

open(INFO, $file); # Open the file
open(OUT, ">OutPutFile.out");

while (<INFO>)
{

chomp($_);
@record=split(/\|/,$_);


if($_=~/(\d*\.0\sDC\sAND\s\d*\.0\sDC)/)
{
$i++;
print OUT "$i $1";
@temp=split(/\|/,$1);
$t="@temp";
$t=~s/\.0\sDC\sAND\s\d*\.0\sDC//g;
chomp($t);
print OUT "$t || V ";
$t1="@temp";
$t1=~s/\d*\.0\sDC\sAND\s//g;
$t1=~s/\.0\s\w*//g;
chomp($t1);
print OUT "$t1 || V \n";

so plz help me out.

regards

Member
 
Join Date: Nov 2006
Posts: 83
#2: Dec 4 '06

re: Reading particular Column in text file


Quote:

Originally Posted by redalpha

I am facing problem in finding a code which should read particular column in text file.

Quote:

Originally Posted by redalpha

@record=split(/\|/,$_);

if($_=~/(\d*\.0\sDC\sAND\s\d*\.0\sDC)/)

If you for instance are interested in the third column:
Expand|Select|Wrap|Line Numbers
  1. if ( $record[2] =~ /(\d*\.0\sDC\sAND\s\d*\.0\sDC)/ )
Newbie
 
Join Date: Dec 2006
Posts: 3
#3: Dec 5 '06

re: Reading particular Column in text file


Quote:

Originally Posted by GunnarH

If you for instance are interested in the third column:

Expand|Select|Wrap|Line Numbers
  1. if ( $record[2] =~ /(\d*\.0\sDC\sAND\s\d*\.0\sDC)/ )

Thanks its working
Reply