Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strip last char from a file

Status
Not open for further replies.
Mar 19, 2004
35
US
What's the easiest way to strip the very last byte from a print file? Specifically, the formfeed char \f 0x0C
I want to keep all other formfeeds intact.

Thanks in advance!
 
sed -e 's/.$//g' file > newFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
You may try something like this:
ff=`echo "\f\c"`
sed -e '$s!'"$ff!!" /path/to/input >output

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks, but those two suggestions cause the whole PCL string at the end to get removed, not just the form feed. Weird.

PCL string =
[(s0p10h0s0b4099T^[&l8d^L

 
You may try something like this:
ff=`echo "\f\c"`
(cat /path/to/input; echo "\r") |
sed -e '$s!'"$ff!!" >output

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
This will replace form-feeds with line-feeds only on the last line of the file...
[tt]
IFS=. printf "\014.\012"|read FF LF
sed "$ s/$FF/$LF/g" file1 > file2
[/tt]
 
Ygor, PHV:

I'm sure I'm entering those commands exactly as you've entered them.

I'm still getting the whole last set of chars removed from the file, not just the form feed.

I wish I could attach the before/after files to show you...

 
You may try something like this:
ff=`echo "\f\c"`
(cat /path/to/input; echo "\n") |
sed -e '$s!'"$ff!!" >output


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Maybe try..

awk 'p{print p};{p=$0};END{sub("\014","\012",p);print p}' file1 > file2

If that doesn't work, perhaps you could post the results of...

od -hc file1 | tail
 
Thanks so much for all the assistance!

I finally figured out that I was using ' instead of ` in places.

What a fool I am for attempting to set foot in the Unix world!

;-)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top