sed: Remove All Digits / Input From Input

in Categories , , , , , , , , , , , , last updated 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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 6 comments/add one below):

6 comment

  1. Hi!
    I’m doing this:

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

    The output is :


    And what I’m trying to get is :


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

    Have a question? Post it on our forum!