Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Parsing Data logger files ...

by choroba (Abbot)
on Oct 06, 2012 at 22:31 UTC ( #997646=note: print w/ replies, xml ) Need Help??


in reply to Parsing Data logger files ...

Do you mean something like this?

#!/usr/bin/perl use warnings; use strict; $/ = "\n1="; while (<>) { my @fields = split /\n/; s/^[1-6]=// for @fields; print +(join ',', @fields[0 .. 5]), "\n"; }
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Parsing Data logger files ...
Download Code
Re^2: Parsing Data logger files ...
by RedTussock (Acolyte) on Oct 07, 2012 at 00:17 UTC
    Awesome thanks ... And the open the folder and process all files in it would look something like ..
    opendir XX, "/somefile/somewhere" or die "Couldn't open the directory +: $!"; while ($_ = readdir (XX)) { $/ = "\n1="; while (<>) { my @fields = split /\n/; s/^[1-6]=// for @fields; print +(join ',', @fields[0 .. 5]), "\n"; }
    Sorry my perl scripting is newb in the extreme ... :-)
Re^2: Parsing Data logger files ...
by RedTussock (Acolyte) on Oct 07, 2012 at 00:40 UTC
    Sorry the previous comment was a bit naff ... where I am at is
    #!/usr/bin/perl use warnings; use strict; opendir DH, "/a/b/c/perl/dl_parser/down/" or die "Couldn't open the d +irectory +: $!"; while ($_ = readdir (DH)) { $/ = "\n1="; my @fields = split /\n/; s/^[1-6]=// for @fields; print +(join ',', @fields[0 .. 5]), "\n"; } exit
    which gets me a list of files and 5 other lines ... :-) like
    101130.TXT,,,,, Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. 240429.TXT,,,,, Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. 110208.TXT,,,,, Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. 081221.TXT,,,,, Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. 100807.TXT,,,,, Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. Use of uninitialized value in join or string at lineJumper.pl line 11. 081219.TXT,,,,,
    So getting close ... need to read each file ... maybe split into modules one that reads the file names from the directory, and one that process's them?. .. then build some interface to ask for the directory and maybe a file name to print the records too.

      The simplest solution would be to call choroba's script as "munge.pl /some/where/*" and let the shell do the directory stuff. "<>" will automatically try to read everything in @ARGV so you don't have to deal with it yourself.

      Otherwise you're on the right track with readdir but you forgot to actually open each individual file.

        Perfect ... and a lesson in spotting the tree in the forest. Thank you both ... I guess now all I have to do is print it too a file.
        Something like
        #!/usr/bin/perl use warnings; use strict; $/ = "\n1="; while (<>) { my @fields = split /\n/; s/^[1-6]=// for @fields; open (MYFILE, '>/a/b/c/perl/dl_parser/logData.txt'); print MYFILE "+(join ',', @fields[0 .. 5]), "\n""; close (MYFILE); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997646]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-08-21 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (144 votes), past polls