Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 702
  • Last Modified:

How to write a script file to insert "form feed" into ASCII file?

I am using SEIKOSHA BP-5780II printer for my Solaris server print job.

I have create an ASCII file from my application but when lp the ASCII file to printer the report does not form feed well and there is no special character in the ASCII file for form feed.

So I need a script file to insert "form feed" into the ASCII file when detected a string start with "REPORT ID".  From the printer manual Hexadecimal & Decimal value for form feed is "[0C]H[10] D".



0
cwchaw
Asked:
cwchaw
1 Solution
 
kiffneyCommented:
Well, if you use perl, you could just do this - (swiped from 'man perlfaq5'):

$file = $ARGV[0];
$old = $file;
$new = "$file.tmp.$$";
$bak = "$file.bak";
open(OLD, "< $old") or die "can't open $old: $!";
open(NEW, "> $new") or die "can't open $new: $!";

while (<OLD>) {
   s/REPORT ID/\fREPORT ID/g;
(print NEW $_) or die "can't write to $new: $!";
}

close(OLD) or die "can't close $old: $!";
close(NEW) or die "can't close $new: $!";
rename($old, $bak) or die "can't rename $old to $bak: $!";
rename($new, $old) or die "can't rename $new to $old: $!";


#run this with
#perl myfile

OR, if you like plain old awk, try

awk '{sub("REPORT ID","\fREPORT ID"); print $0}' myreport.txt > fixedreport.txt

0
 
festiveCommented:
you could alter the printer interface file on the unix system.
Most modern unixes have options within their interface files for adding form feeds, carriage returns, linefeeds etc.

Under Solaris:
/etc/lp/interfaces

Some Others:
/usr/spool/lp/interfaces
/usr/spool/lpd/interfaces

these are usually just shell scripts and can incorporate calls to other programs if required.

something you may want to look at before you do this and enter into the cycle of pain (direct unix printing) is to get a simple pc (does not even have to be dedicated) and run a program like easyspooler or RPM , these offer very funky configuration options and will handle by default the formfeeds etc.

(one thing to watch is that it is set to RAW mode: consult the manufacturers of the above for more specific info, but these programs have been a God-Send in environments I have worked in and they allow unix to do what it was born to : grunt merrily in the corner and not attempt fancy printing... Horses for Courses)
0
 
cwchawAuthor Commented:
Can I use 'sed' or' 'tr' to substitute a word in an ASCII file?  

If yes, how?  

Please include an example of a script file?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
festiveCommented:
#!/bin/sh -p
# Word Changer: substitute word for word
# and provide new file on standard out.
# Usage:
# chngword <file> <old_word> <new_word>
$FILE_NAME=$1
$OLD_WORD=$2
$NEW_WORD=$3
cat $FILE_NAME |
    sed 's/$OLD_WORD/$NEW_WORD/g'
0
 
kiffneyCommented:
sed apparently can't insert special characters like form feed.  tr can't do it because it translates individual characters and won'rt recognize a string like REPORT ID.
0
 
ozoCommented:
Well, if there's some other non-specil character that isn't being used, you might use sed to insert it, then use tr to translate it into a form feed.
But it still seems easier just to use
perl -i.bak -pe 's/(REPORT ID)/\f$1/g' myfile
0
 
festiveCommented:
sed can substitute any characters that ed or vi can , try using octal equivalents like \013 etc or escaped ctrl codes.
0
 
ianBCommented:
We have opened up a new Solaris Topic Area.  

To increase the visibility of questions, we moved questions we felt
appropriate to the new Solaris Topic Area where they will be easier for
Solaris experts to find and answer. You may view your question at
http://www.experts-exchange.com/Computers/Operating_Systems/Solaris/ 

If you have any questions about the new topic area you can contact
Community Support by posting a comment at the following URL or by
emailing us at cs@experts-exchange.com.
http://www.experts-exchange.com/Customer_Service/Experts_Exchange/ 

Ian
Community Support @ Experts Exchange

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now