sed: Remove All Digits / Input From Input

by on February 22, 2008 · 4 comments· last updated at December 22, 2008

Q. How do I remove all digits or number from my text file or input using sed command?

A. You need to use regular expression to remove digits or number from input. For example, 's/[0-9]*//g' will remove all numbers from the input.

Remove all digits

Type the following command:
$ echo 'This is a test 12335 and 669384 535xy4' | sed 's/[0-9]*//g'
Sample output:

This is a test  and  xy

You can remove all digits from a text file:
$ sed 's/[0-9]*//g' input.txt
$ sed 's/[0-9]*//g' input.txt > output.txt



You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 4 comments… read them below or add one }

1 dimka August 19, 2009 at 9:46 am

But how can i remove all, but digits?!

Reply

2 Vivek Gite August 19, 2009 at 12:04 pm

Try:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[^0-9]*//g'

Reply

3 dimka August 21, 2009 at 6:04 am

Oh, thanks! That’s what I was looking for!

Reply

4 np September 5, 2012 at 2:56 pm

Hi!
I’m doing this:

echo 'something=1234
something=12345
andsomething=1234&somethingelse&something=1234
something=2345' | sed 's/something=1234[^0-9]/something=9999/g'

The output is :

something=1234
something=12345
andsomething=9999&somethingelse&something=1234
something=2345

And what I’m trying to get is :

something=9999
something=12345
andsomething=9999&somethingelse&something=9999
something=2345

Why isn’t it working when the pattern is at the end of the line ? What a pain….
Help, anyone ?

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , ,

Previous Faq:

Next Faq: