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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ex editor question 2

Status
Not open for further replies.

vlz

IS-IT--Management
Aug 11, 2002
56
IL
Hi,
I need to delete the last character in a file by using
ex commands.
I know for example how to delete the last line by this command:
echo "d\nw\nq"|ex my_file

How can I do this for a character?

Thanks in advance,
Vadim
 
Hi,

Use this instruction sequence
Code:
ex /path/to/your_file.txt 1>/dev/null 2>&1 <<- EOEX
        $
        s/.$//
        wq
EOEX
 
Thanks for your help!
It works fine for printable characters.
How can I delete non-printable character in case I know
only HEX code of it?
 
Hi,

How does the characters present in the file (upper/lower hexa) ?
The non printable are located everywere in the file ?
If possible, post a part of the file wil help.
 
I need to delete "new line - LF(hex=0A)" character that was added after
"end of file - SOH(hex=01)" character.
Please see example:
00 00 00 00 00 00 00 01 0A
 
ex isn't a binary editor.
You may consider to use dd to copy all but the last character.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
If you have the xxd command you can try
Code:
xxd -p /input/file | sed 's/..$//' | xxd -r -p
or shell out of ex, e.g.:
Code:
ex -s /data/file <<EOF
%!xxd -p
\$s/..$//
%!xxd -r -p
w
q
EOF

Note: you may have to escape the '$' char in your shell.

Cheers,
ND [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top