Solved

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

Posted on 2000-04-14
8
657 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
8 Comments
 
LVL 4

Expert Comment

by:kiffney
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 2

Accepted Solution

by:
festive earned 200 total points
Comment Utility
#!/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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Expert Comment

by:kiffney
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now