If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > inserting print escape codes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-03-03, 01:43
Douglas Anderso Douglas Anderso is offline
Registered User
 
Join Date: Jul 2003
Posts: 6
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.
Reply With Quote
  #2 (permalink)  
Old 10-05-03, 07:28
fla5do fla5do is offline
Registered User
 
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 08:40.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On