Re: Ordering string of commands in a file



Raghuramaiah Gompa wrote:
> I have a file that has lines like the following:
>
> Titl1=B2a
> Command1=c:\chi\cw.exe
> Title2=f2a
> Directory1=c:\chi
> Type1=1
> Command2=c:\chi\cw.exe
> Directory2=c:\chi
> Options2=%@%
> Type11=2
> Title14=Ma3
> Command14=c:\chi\cpb.bat
> Options14=c:\temp\temp.bin
> Use long names3=1
> Title12=Dir
> Command12=Tfd
> Title13=a2h
> Command13=c:\bat\a2h.bat
> Options13=%@dpn%
> Show13=2
> Command31=C:\bat\tview.bat
> Use long names31=1
> Title31=tview
> .....
>
> Basically Title,Command, Show,... constitute a group of commands that are associated with the
> name described in Title. Now I want to reorder them in the alphabetical order of names described in
> Title. For instance, the new file should have :
>
> Title1=a2h
> Command1=c:\bat\a2h.bat
> Options1=%@dpn%
> Show1=2
>
> and all the lines (Title2=B2a, ..) are changed accordingly (because or the order a2h, B2a, Dir, f2a, Ma3, .... )
>
> How can I achieve this? Please help. .. Raghu

Perhaps something like this:

#!/usr/bin/perl
use warnings;
use strict;


my %hash = do { local $/; grep length, split /^(Title\d+=.+)/m, <DATA> };

print
map $_->[ 1 ],
sort { lc $a->[ 0 ] cmp lc $b->[ 0 ] }
map [ /=(.+)/, "$_$hash{$_}" ],
keys %hash;


__DATA__
Title1=B2a
Command1=c:\chi\cw.exe
Title2=f2a
Directory1=c:\chi
Type1=1
Command2=c:\chi\cw.exe
Directory2=c:\chi
Options2=%@%
Type11=2
Title14=Ma3
Command14=c:\chi\cpb.bat
Options14=c:\temp\temp.bin
Use long names3=1
Title12=Dir
Command12=Tfd
Title13=a2h
Command13=c:\bat\a2h.bat
Options13=%@dpn%
Show13=2
Command31=C:\bat\tview.bat
Use long names31=1
Title31=tview




John
--
use Perl;
program
fulfillment
.



Relevant Pages

  • Re: A _Bunch_ of Article_XXXX commands in _One_ send buffer.
    ... Speaking of perl... ... I love macros, they remove a lot of redundancy and other ugliness. ... issuing Article_XXXX commands one at a time. ... Terminals have a baud rate, ...
    (news.software.readers)
  • Re: Simple EDT or TPU init file
    ... The keys work whether I type set term ... Cheers, John ... using SHOW TERMINAL/FULL I find the keypad is usually ... > Clearly we need to put the necessary DCL setup commands into ...
    (comp.os.vms)
  • Re: Interactive apps with tcl
    ... I am trying to build an interactive test application. ... would like to generate interactive commands to an existing ... I think you will want to look at the Expect extension to Tcl. ... If you prefer to work in Perl, ...
    (comp.lang.tcl)
  • RE: Non-printing Characters
    ... Subject: Non-printing Characters ... commands sent to the printer. ... You've got Perl! ... somefile | less' to see what I can see of a file's format. ...
    (perl.beginners)
  • Re: Difference between Cygwin and DOS handling of string input
    ... Ton of userland tools that make work possible (perl, sed, awk, grep, ... cmd.exe is a shell in that it's a TTY that lets you run commands, ...
    (comp.lang.c)