Operating System - HP-UX
1833974 Members
1876 Online
110063 Solutions
New Discussion

Re: tr commad to change print escapes

 
SOLVED
Go to solution
Barbara Kramer
Frequent Advisor

tr commad to change print escapes

Hi,
just changing invoice printing from HP to Sharp model -

Now I have to change printing skripts from
[esc]&l5H to [esc]&l4H. This is what I used: tr '&l5H' '&l4H' file2

this is not working, it distroyes my file2
can anyone help?

Thanks Barbara
live is great !!
8 REPLIES 8
Mel Burslan
Honored Contributor

Re: tr commad to change print escapes

use double quotes and preceed the & signs with a "\" (backslash) as they have special meaning in the command line (as in send process to background)
________________________________
UNIX because I majored in cryptology...
Mel Burslan
Honored Contributor
Solution

Re: tr commad to change print escapes

actually I am not sure if you can do this using tr. Use of sed is a better alternative here:

cat file1 | sed -e "1,\$s/\&l5H/\&l4H/g" >file2

hope this helps
________________________________
UNIX because I majored in cryptology...
Barbara Kramer
Frequent Advisor

Re: tr commad to change print escapes

Hi,

I used tr "\ &l5H" "\ &l4H" file2

the escape sequense of
file1=&f5X &l5H (10U (s0p10.00h12.0v0s0b3T
file2=&f4X &l4H (10U (s0p10.00h12.0v0s0b3T

meaning it did not only change the &l5H, but also the preceeding &f4X &l4H , see above

Any other ideas?
Thanks again for helping
Barbara
live is great !!
A. Clay Stephenson
Acclaimed Contributor

Re: tr commad to change print escapes

tr will not do this. You use of tr simply relaces each occurence in the first string with its corresponding character in the second string . & -> &, l -> l, 5 -> 4, H -> H; the net result is that every '5' in file 1 is replaced by '4'. You seem to think tr does pattern matching.

You need to use sed, awk, or Perl. Any of these can look for patterns (rather than individual characters) and take actions. I'm sure someone will post a solution but I choose not to because if you are going to use UNIX, you need to learn regular expressions. You should be able to find some very easy sed examples with just a little bit of searching.
If it ain't broke, I can fix that.
Barbara Kramer
Frequent Advisor

Re: tr commad to change print escapes

Hi Mel,

thanks for you sed command. It worked very nicely!
since I am not so great on sed, could you also tell me, how to add an additional change? What I need to change is:
&l5H to &l4H and &l20H to &l22H

can that be done in one step, or do I have to use a tmpfile, like:
cat $1| sed -e "1,\$s/\&l5H/\&l4H/g" >tmp.prn
cat tmp.prn| sed -e "1,\$s/\&l20H/\&l22H/g"

thanks again
Barbara
live is great !!
Barbara Kramer
Frequent Advisor

Re: tr commad to change print escapes

Hello Clay,
I agree being able to move around best way possible in a system. I did look up sed skripting and finished my job. Yet having Mel's answer is terrific, if one is really pressed for time.
Thanks to both of you !!
Barbara
live is great !!
Barbara Kramer
Frequent Advisor

Re: tr commad to change print escapes

thanks again!!
live is great !!
Mel Burslan
Honored Contributor

Re: tr commad to change print escapes


Quote:
_________________________________________
can that be done in one step, or do I have to use a tmpfile, like:
cat $1| sed -e "1,\$s/\&l5H/\&l4H/g" >tmp.prn
cat tmp.prn| sed -e "1,\$s/\&l20H/\&l22H/g"
_________________________________________

you can do it either way, i.e., the way you proposed in the quoted text above or

**********
cat $1| sed -e "1,\$s/\&l5H/\&l4H/g" | sed -e "1,\$s/\&l20H/\&l22H/g"
**********
(in case itrc breaks the line due to the new and improved forums code, all in between the two "**********" lines is actually a single line command)

multiple pipes are godsent and I missed them dearly when I was doing VMS sysadmin in a darker period of my career :)
________________________________
UNIX because I majored in cryptology...