Reputation: 33
I have a .txt file where the last column includes a number pattern after the text like 'Baker 2-13' or 'Charlie 03-144.' I would like to remove all the digits at the end of the line, and just be left with Baker and Charlie. I have tried piping the sed command at the end of my awk statement, with no success.
sed -E 's/[0-9]{1,2}"-"[0-9]{1,3}$//'
I've tried adding the space and carriage returns to my sed command, but still no luck.
sed -E 's/[0-9]{1,2}"-"[0-9]{1,3}\s\r$//'
I've also tried this, but it only works when I echo a text sample, it doesn't work on each line of my .txt file
echo "CHARLIE 02-157" | sed -E 's/[0-9]*([0-9])+\-[0-9]*([0-9])+$//'
Any ideas?
Upvotes: 1
Views: 657
Reputation: 1726
Simple sed solution
sed 's/[- 0-9]*$//'
This will delete trailing dashes, blanks and numbers!
Upvotes: 0
Reputation: 784898
This should work:
sed -i.bak -E 's/[0-9]{1,2}-[0-9]{1,3}$//' file
cat file
Baker
Charlie
You don't need to quote hyphen in the pattern.
Upvotes: 2