remove last 3 characters from a line

ambuli
ambuli used Ask the Experts™
on
Hi Experts,
I need to remove all the last 3 characters from the line for every line in the file.
How can I do this?
It would be great if you can give me a general way of removing any number of characters from a line.
Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


sed 's/...$//' file > newfile


Good Luck,
Kent
Most Valuable Expert 2013
Top Expert 2013

Commented:
CUT=3
awk -v C=$CUT '{print substr($0,1,length($0)-C)}' inputfile

wmp
Top Expert 2008

Commented:
If you want to make the change inline (that is, without writing the changes to a new file) you can use the "-i" parameter to sed like that:

sed -i 's/...$//' file

If you need to remove more than three characters at the end of the line and don't want to mess around with the big amount of dots then, just use this way:

sed -i 's/.\{3\}$//' file

and replace the 3 in the curly brackets with whatever number you need.

Author

Commented:
Thank you.  Is there a way to do this in xemacs?

Author

Commented:
Hi agriesser, woolmilkporc:
I did not see your post before. Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial