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

Hmm... looking at some of the lines of 'template.txt'. You are attempting to mod some sort of Star Trek video game I presume? If so you may just want to tell us which game and what you are trying to do exactly. If any Monk here happens to be familiar with or even have the game they can probably go look at the files themselves and see exactly what you are talking about.

Beyond that, I know you probably hate the idea of putting in the time to learn the rudiments of a computer language, but Perl isn't so difficult to pick up, and even something like this very short tutorial can teach you everything you need and more to do what you are asking. The far greater upside of sticking it out and learning Perl yourself would be that if you are doing this sort of thing a lot, you will be amazed at how much more adept and proficient you can be at it with the Swiss Army Chainsaw that is Perl in your toolbox. :-)

Just another Perl hooker - will code for food
  • Comment on Re: re-ordering lines of text in a file?

Replies are listed 'Best First'.
Re^2: re-ordering lines of text in a file?
by moddingforfun (Initiate) on Nov 30, 2016 at 17:28 UTC

    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.

    I posted more info/lengthy examples in another response on this same ?node?thread?
      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.