?
Solved

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

Posted on 2000-04-14
8
Medium Priority
?
694 Views
Last Modified: 2013-12-27
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
Comment
Question by:cwchaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:kiffney
ID: 2716729
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
 
LVL 2

Expert Comment

by:festive
ID: 2726661
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
 

Author Comment

by:cwchaw
ID: 2729699
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Accepted Solution

by:
festive earned 600 total points
ID: 2734089
#!/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
 
LVL 4

Expert Comment

by:kiffney
ID: 2736896
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
 
LVL 84

Expert Comment

by:ozo
ID: 2736958
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
 
LVL 2

Expert Comment

by:festive
ID: 2740155
sed can substitute any characters that ed or vi can , try using octal equivalents like \013 etc or escaped ctrl codes.
0
 
LVL 5

Expert Comment

by:ianB
ID: 2855608
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question