How do I remove all (text, special characters, white spaces, tabs etc) from my text file (input) except numbers (digits) using sed command?
You need to use simple regular expression to remove all but numbers from the input. For example, ‘s/^[0-9]*//g’ will remove all but numbers from the input. Type the following command: $ echo 'This is a test. 123456789 and 2nd number is 34. 3M3i4x5' | sed 's/[^0-9]*//g' You can remove all except digits from a text file: