Avatar of ambuli
ambuliFlag for United States of America

asked on 

remove last 3 characters from a line

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.
Linux

Avatar of undefined
Last Comment
ambuli
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

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

wmp
Avatar of agriesser
agriesser
Flag of Austria image

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.
Avatar of ambuli
ambuli
Flag of United States of America image

ASKER

Thank you.  Is there a way to do this in xemacs?
Avatar of ambuli
ambuli
Flag of United States of America image

ASKER

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

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo