Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > Reading and writing multicolumn text files with Perl

Forgot Password?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 05-24-2005   #11 (permalink)
scm
Linux Engineer
 
Join Date: Feb 2005
Posts: 1,004
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?
scm is offline  


Reply With Quote
Old 05-24-2005   #12 (permalink)
Trusted Penguin
 
Cabhan's Avatar
 
Join Date: Jan 2005
Location: Boston, MA, USA
Posts: 2,691
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.
__________________
DISTRO=Gentoo
Registered Linux User #388732
Gentoo Linux, 410 GB HD, 1.2 GB RAM, Fluxbox, These are a Few of my Favorite Things
Cabhan is offline   Reply With Quote
Old 05-24-2005   #13 (permalink)
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
hernandeangelis is offline   Reply With Quote
Old 05-24-2005   #14 (permalink)
Trusted Penguin
 
Cabhan's Avatar
 
Join Date: Jan 2005
Location: Boston, MA, USA
Posts: 2,691
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?
__________________
DISTRO=Gentoo
Registered Linux User #388732
Gentoo Linux, 410 GB HD, 1.2 GB RAM, Fluxbox, These are a Few of my Favorite Things
Cabhan is offline   Reply With Quote
Old 05-24-2005   #15 (permalink)
Just Joined!
 
hernandeangelis's Avatar
 
Join Date: Mar 2005
Location: Planet Earth
Posts: 79
Yes, it helps.

Thanks

Hernan
hernandeangelis is offline   Reply With Quote
Old 05-25-2005   #16 (permalink)
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.
Santa's little helper is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 04:34 PM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2