Reading particular Column in text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redalpha
    New Member
    • Dec 2006
    • 3

    Reading particular Column in text file

    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.ou t");

    while (<INFO>)
    {

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


    if($_=~/(\d*\.0\sDC\sAN D\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
  • GunnarH
    New Member
    • Nov 2006
    • 83

    #2
    Originally posted by redalpha
    I am facing problem in finding a code which should read particular column in text file.
    Originally posted by redalpha
    @record=split(/\|/,$_);

    if($_=~/(\d*\.0\sDC\sAN D\s\d*\.0\sDC)/)
    If you for instance are interested in the third column:
    Code:
    if ( $record[2] =~ /(\d*\.0\sDC\sAND\s\d*\.0\sDC)/ )

    Comment

    • redalpha
      New Member
      • Dec 2006
      • 3

      #3
      Originally posted by GunnarH
      If you for instance are interested in the third column:
      Code:
      if ( $record[2] =~ /(\d*\.0\sDC\sAND\s\d*\.0\sDC)/ )
      Thanks its working

      Comment

      Working...