Solved

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

Posted on 2000-04-14
8
684 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
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.

734 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