I have a text file which contains a series of same line except at the end. eg
lesi-1-1500-1
lesi-1-1500-2
lesi-1-1500-3
how can I remove the last number? it goes upto 250
CodePudding user response:
You can do it with Awk by breaking it into fields.
echo "lesi-1-1500-2" > foo.txt
echo "lesi-1-1500-3" >> foo.txt
cat foo.txt | awk -F '-' '{print $1 "-" $2 "-" $3 }'
The -F
switch allows us to set the delimiter which is -
. Then we just print the first three fields with -
for formatting.
CodePudding user response:
to change in the file itself
sed -i 's/[0-9]\ $//' /path/to/file
or
sed 's/[0-9]\ $//' /path/to/file > /path/to/output
see example