sed: Remove All Digits / Input From Input

by Vivek Gite on February 22, 2008 · 3 comments

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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 3 comments… read them below or add one }

1 dimka August 19, 2009

But how can i remove all, but digits?!

Reply

2 Vivek Gite August 19, 2009

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

Reply

3 dimka August 21, 2009

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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 11 + 8 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: