Am trying to use the sed command to remove all the text before the first numeric character in all the lines, by using the following

sed 's/.*[0-9]//' temp1.txt

However, it is removing all the text up to the last numeric character.

  • you should add sample input/output to clarify whether or not you want to remove the first digit as well... you text says before but the code you tried removes the digit – Sundeep Oct 28 '17 at 15:25
  • see also stackoverflow.com/questions/5319840/… – Sundeep Oct 28 '17 at 15:25

this is due to eager algorithm of sed.


sed 's/^[^0-9]*//' temp1.txt


  • ^ begining of line
  • [^0-9] any char but 0-9
  • * multiple time
  • 1
    This will also remove the first numeric character, if this is not desired, leave off the second [0-9] – crater2150 Oct 28 '17 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.