Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: re-ordering lines of text in a file?

by moddingforfun (Initiate)
on Nov 30, 2016 at 17:28 UTC ( [id://1176948]=note: print w/replies, xml ) Need Help??


in reply to Re: re-ordering lines of text in a file?
in thread re-ordering lines of text in a file?

In response to your request ...

The website is http://www.fleetops.net

The tutorial ... a question ... The "arrays" ... input is a fixed expression? By that I mean 'pattern match'. grep for '^green' in a file, that is exactly what you get. The result is the first 'green' starting a line in that file. The problem I face, is the rest of the line. The rest of the line has the "value" of the key-pair.

The analogy / examples :
The key-pairs ( variable = value ) are denoted by the 'equal sign'. Example #1 shieldgeneratortargethardpoints = "hp01" "hp02" "hp03" "hp04" "hp05" " +hp06" "hp07" "hp08" "hp09" "hp10" Example #2 shieldgeneratortargethardpoints = "hp01" "hp02" "hp03" "hp04" "hp05" " +hp06" "hp07" Example #3 shieldgeneratortargethardpoints = "hp07" "hp08" "hp09" "hp10" "hp11" " +hp12" "hp13" "hp14" "hp15"

Notice the variance the values ( number of as well )? I am puzzled how this could ... be input without major problems. The "values" are highly random in 'length/style/number of' terms. That was fatal to bash shell script exact pattern matching.

I posted more info/lengthy examples in another response on this same ?node?thread?

Replies are listed 'Best First'.
Re^3: re-ordering lines of text in a file?
by poj (Abbot) on Nov 30, 2016 at 18:20 UTC
    I am puzzled how this could ... be input without major problems

    If you need to create a separate record for each value then try

    #!perl use strict; use DBI; use Text::ParseWords 'quotewords'; open OUT,'>','output.txt' or die "$!"; my @infiles = glob("*.odf"); for my $infile (@infiles){ open IN,'<',$infile or die "Could not open $infile : $!"; print "Reading $infile.."; my $count=0; while (<IN>){ chomp; ++$count; my ($key,$string) = split /\s*=\s*/,$_; my @values = quotewords('\s+',0,$string); for my $i (1..@values){ printf OUT "%-30s %-35s %-35s %5d\n", $infile,$key,$values[$i-1],$i; } } print "$count lines read\n"; }
    poj

      Thank you.

      You got the old mental gears turning, and even pointed me in the right direction with that tutorial.

      Figured out *why* the shell script was not working .... the 'expression'. Instead of grep 'term-goes-here', it needed to be grep 'term-goes-here.*'. That returns the rest of the line with the 'expression'.

      I learned something anyways ... Thank You.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-25 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found