LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2003, 03:49 PM   #16
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79

If that is true then you can use this else statement at the top:
else{
if($name eq "029"){$var{'028'}.=",".join(':',@data)."\n"}
else{$var{$name}.=join(':',@data)}
}

This way both elements are put into the 028 variable.

This will look much better if you use absolute positioning.
 
Old 09-03-2003, 11:30 PM   #17
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Original Poster
Rep: Reputation: 58
cool,

That's going to work.

When you say absolute positioning does this mean that I can set the position of the output to match the template or would it be more to it than that?

I guess I can use sed to put some code into the template as it is converted to code.

The unix system we use has the same problem, you need to look at the output and adjust the tempate to correct it. However it's still better than the dos one we have now. It is preset into a format that cannot be changed. Also the output is gone before you can see it (no scrolling) so it's almost useless while it's running.

If you get time maybe you can show me an example of positioning.

Do you think there is an advantage using perl over sed?

I have made this from my little sed script, Seems a bit long, but maybe it's faster, better?

Code:
#!/usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
  if 0;
$0 =~ s/^.*?(\w+)[\.\w+]*$/$1/;

use strict;
use Symbol;
use vars qw{ $isEOF $Hold %wFiles @Q $CondReg
             $doAutoPrint $doOpenWrite $doPrint };
$doAutoPrint = 1;
$doOpenWrite = 1;
# prototypes
sub openARGV();
sub getsARGV(;\$);
sub eofARGV();
sub printQ();

# Run: the sed loop reading input and applying the script
#
sub Run(){
    my( $h, $icnt, $s, $n );
    # hack (not unbreakable :-/) to avoid // matching an empty string
    my $z = "\000"; $z =~ /$z/;
    # Initialize.
    openARGV();
    $Hold    = '';
    $CondReg = 0;
    $doPrint = $doAutoPrint;
CYCLE:
    while( getsARGV() ){
        chomp();
        $CondReg = 0;   # cleared on t
BOS:;
# #!/bin/sed -f
# s/@\(0..\)/$var{'\1'}/g
{ $s = s /@(0..)/\$var{'${1}'}/sg;
  $CondReg ||= $s;
}
EOS:    if( $doPrint ){
            print $_, "\n";
        } else {
            $doPrint = $doAutoPrint;
        }
        printQ() if @Q;
    }

    exit( 0 );
}
Run();

# openARGV: open 1st input file
#
sub openARGV(){
    unshift( @ARGV, '-' ) unless @ARGV;
    my $file = shift( @ARGV );
    open( ARG, "<$file" )
    || die( "$0: can't open $file for reading ($!)\n" );
    $isEOF = 0;
}

# getsARGV: Read another input line into argument (default: $_).
#           Move on to next input file, and reset EOF flag $isEOF.
sub getsARGV(;\$){
    my $argref = @_ ? shift() : \$_;
    while( $isEOF || ! defined( $$argref = <ARG> ) ){
        close( ARG );
        return 0 unless @ARGV;
        my $file = shift( @ARGV );
        open( ARG, "<$file" )
        || die( "$0: can't open $file for reading ($!)\n" );
        $isEOF = 0;
    }
    1;
}

# eofARGV: end-of-file test
#
sub eofARGV(){
    return @ARGV == 0 && ( $isEOF = eof( ARG ) );
}

# makeHandle: Generates another file handle for some file (given by its path)
#             to be written due to a w command or an s command's w flag.
sub makeHandle($){
    my( $path ) = @_;
    my $handle;
    if( ! exists( $wFiles{$path} ) || $wFiles{$path} eq '' ){
        $handle = $wFiles{$path} = gensym();
        if( $doOpenWrite ){
            if( ! open( $handle, ">$path" ) ){
                die( "$0: can't open $path for writing: ($!)\n" );
            }
        }
    } else {
        $handle = $wFiles{$path};
    }
    return $handle;
}

# printQ: Print queued output which is either a string or a reference
#         to a pathname.
sub printQ(){
    for my $q ( @Q ){
        if( ref( $q ) ){
            # flush open w files so that reading this file gets it all
            if( exists( $wFiles{$$q} ) && $wFiles{$$q} ne '' ){
                open( $wFiles{$$q}, ">>$$q" );
            }
            # copy file to stdout: slow, but safe
            if( open( RF, "<$$q" ) ){
                while( defined( my $line = <RF> ) ){
                    print $line;
                }
                close( RF );
            }
        } else {
            print $q;
        }
    }
    undef( @Q );
}

It works fine, I'm just wondering if there is an advantage.


Congrats on the Mod status, We're glad you have decided to take it.

Last edited by DavidPhillips; 09-03-2003 at 11:34 PM.
 
Old 09-04-2003, 01:44 PM   #18
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
The escape sequences are like this
#\033[TOP;LEFTH

just replace TOP and LEFT with the TOP and LEFT positions. so for your template it may be:
Code:
\033[2;30H *********** OBSERVERS LOG **********

\033[4;5HClient:$var{'001'}\033[4;35HContractor:$var{'002'}\033[4;65HCrew:$var{'003'}

\033[6;7HDate:$var{'036'}\033[6;41HTime:$var{'035'}\033[6;64HSwath:$var{'033'}

\033[8;2HSystem Parameters..

\033[10;2HAux Channels
\033[11;5HSample Rate:$var{'015'} usec\033[11;35HPreamp Gain:$var{'017'} dB
\033[12;11HAlias:$var{'013'} Hz $var{'014'} dB/Oct\033[12;40HLowcut:$var{'011'} Hz $var{'021'} dB/Oct\033[12;65HNotch:$var{'012'} Hz

\033[14;2HData Channels
\033[15;5HSample Rate:$var{'025'} usec\033[15;35HPreamp Gain:$var{'027'} dB
\033[16;11HAlias:$var{'023'} Hz $var{'024'} dB/Oct\033[16;40HLowcut:$var{'020'} Hz $var{'021'} dB/Oct\033[16;65HNotch:$var{'022'} Hz

\033[18;2HSource Parameters..

\033[20;5HStart Frequency:$var{'040'} Hz\033[20;40HEnd Frequency:$var{'041'} Hz
\033[21;9HStart Taper:$var{'044'}\033[21;44HEnd Taper:$var{'045'}
\033[22;8HSweep Length:$var{'042'} ms\033[22;43HStack Size:$var{'038'}

\033[24;5HFile Number: $var{'037'}\033[24;40HRecord Length:$var{'026'}\033[24;60HTime Break:$var{'034'} usec

\033[26;2HActive Spread..
\033[27;5HLine...\033[27;30HTraces:
$var{'028'}
 
Old 09-04-2003, 11:24 PM   #19
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Original Poster
Rep: Reputation: 58
ok, That's great.

I will look at setting this up.



Any recommendation on a good perl book for beginners.


Thanks again
 
Old 09-05-2003, 12:22 PM   #20
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I'm afraid I'm not really a book person. The only one I have is "PERL, CGI and JAVASCRIPT Complete" but this is mostly web based stuff (this was the reason I started with perl in the first place)

All the answers I have needed I found on the web.

The positioning should work with your awk script too. As for the speed and performance difference I have no idea. I think you would need to run some tests with the live data.
 
Old 09-05-2003, 12:54 PM   #21
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Original Poster
Rep: Reputation: 58
cool

I guess I will start with the man pages.
 
Old 09-05-2003, 12:56 PM   #22
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Any questions just give me a shout. (I usually lurk about the programming forum anyway)
 
Old 09-05-2003, 12:57 PM   #23
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Original Poster
Rep: Reputation: 58
ok, thanks
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script text replacement... matthurne Programming 4 06-07-2011 06:46 PM
Shell Script - String Replacement revof11 Programming 7 11-29-2005 06:38 AM
text editing from a script vogelbaugh Linux - General 2 09-22-2005 12:53 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
Need text pattern compare script kscott121 Linux - Software 4 05-10-2004 01:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration