Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2003
    Posts
    6

    Unanswered: inserting print escape codes

    I built a little shell script to handle the inserting of trigger codes to an ascii print file...basically I have a file with the codes I need at the top of the print file and at the bottom, I cat them all together with the current print data and send to another print queue. It works well...

    Now I want to actually insert codes into the middle of the file...ie: I want to goto line 2 and insert some stuff into the begining of that line, or I want to search for a paticular word and insert stuff there...I need help...I'd like to do this all as variables (I mean I don't want to write an acutal data file, unless you can tell me how to create a filename that is random so that if this script is being run by multiple users it won't overwrite..

    My current script..

    #!/bin/sh
    QUEUE=printerqueue
    HEADER=/usr/local/lib/header.file
    TRAILER=/usr/local/lib/trailer.file
    options$5
    shift 5
    for FILE in $*
    do
    cat $HEADER $FILE $TRAILER | lp -d $QUEUE
    done
    exit 0

    Thoughts...Any help would be appreciated...

    Doug.

  2. #2
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Use this

    # example 1
    cat OLDFILE | awk '{
    i=i+1
    if ( i = 2 )
    {
    print "Hallo" $0 >> "NEWFILE"
    }
    else
    {
    print $0 >> "NEWFILE"
    }
    }'
    # example 2
    cat OLDFILE | awk '{
    if ( $1 = "Mike" )
    {
    print "Hallo" $0 >> "NEWFILE"
    #print "^M" $0 >> "NEWFILE"
    #print "^L" $0 >> "NEWFILE"
    #print "^[" $0 >> "NEWFILE"
    }
    else
    {
    print $0 >> "NEWFILE"
    }
    }'


    In vi use in insertmode CTRL-v to insert keycodes or esc-codes. It takes effect for one character. Use CTRL-v again for the next character.
    for example:
    CTRL-v RETURN gets an ^M. In vi you see two charakters, but it is only one charakter (DEZ 13) Carrige Return.

    Use CTRL-v CTRL-L and you get a ^L ( Form-Feed to a printer )
    Use CTRL-v ESC and you get a ^[ ( ESC-character )

    Greetings from Germany
    Peter F.
    Last edited by fla5do; 10-05-03 at 09:40.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •