Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 16 of 16
Originally Posted by Cabhan So my regexp line looks like: Code: /([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)/; And you thought my suggestion was pretty crazy?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044

    Quote Originally Posted by Cabhan
    So my regexp line looks like:

    Code:
    /([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)/;
    And you thought my suggestion was pretty crazy?

  2. #12
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    If the file is plain text, it doesn't matter what your keyboard is set to. If you have a . , it will be a . . If you have a , , it will be a , .

    And scm, yours is crazy cool. Mine is crazy complicated.


    And if you're interested, I think the problem with scm's solution could be fixed by doing:

    Code:
    ($v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9) = split;
    split without anything else is the same as "split /\s+/, $_". Which we don't need.

  3. #13
    Just Joined! hernandeangelis's Avatar
    Join Date
    Mar 2005
    Location
    Planet Earth
    Posts
    79
    Well, I finally did it with PERL, here is the code:

    open (INFILE, "XXXX");
    open (OUTFILE, "> YYYY");
    while (<INFILE>)
    {
    ($v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9) = split;
    $xf = $v1 + $v6;
    $yf = $v2 + $v7;
    if ( $v5 == 1 ) {
    print OUTFILE $v1, "\t", $v2, "\t", $xf, "\t", $yf, "\n";
    }
    }
    close INFILE;
    close OUTFILE;

    Apart from the "split" function, there is other thing that my poor brain has noticed: the ">" symbol is seems to have more meanings other than to point the direction of the process, or what?

    There is no hope with awk in my computer (a P4, 2.4 GHz, 1Gb RAM with SuSE9.1 personal). It can read and print values in decimal form. It can even calculate with decimals in the console, but not through the program. Here is the code:

    {
    if ($5 == 1)
    { OFS = "\t" ; ORS = "\n" ; print $1, $2, $1 + $6, $2 + $7 ; }
    }

    It still produces things without decimal values like this:

    64 414 100 432
    64 439 71 406
    64 464 67 465
    64 489 66 491
    64 539 70 563
    64 564 72 595
    64 589 30 619
    64 639 51 675

    So, the question is: does the function "BEGIN" has something to do here? I do not really understand very well its meaning and much less how to use it. Well I think that would be a matter for another topic. I could finally make this PERL code to work and that was thanks to your help guys!!! Thanks to Cabhan, Steve and Santa's little helper!!!

    Hernan

  4. #14
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    When you open a file, you specify one of 3 things:

    < - Receive input
    > - Overwrite file and direct output
    >> - Append to file and direct output

    So by running

    Code:
    open OUTFILE, "> yyy"
    You are actually wiping all previous data in that file, whereas

    Code:
    open OUTFILE, ">> yyy"
    Would take the file, leave all existing data, and add on the new output to the end.


    Does that help?

  5. #15
    Just Joined! hernandeangelis's Avatar
    Join Date
    Mar 2005
    Location
    Planet Earth
    Posts
    79
    Yes, it helps.

    Thanks

    Hernan

  6. #16
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    The BEGIN rule gets executed before anything is read from the input
    file(s).I don't imagine it has anything to do with the strange results
    you're getting.

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •