Solved

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

Posted on 2000-04-14
8
676 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
festive earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
llcommand 6 109
Bad Block Relocation for Synchronous GLVM AIX 7.1 2 83
cron job says it ran, no results 25 135
SCO 5.0.7 on HP Proliant DL380 G5 will not shutdown properly. 6 85
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

738 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