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
🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.
🐧 6 comments so far... add one ↓
🐧 6 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
But how can i remove all, but digits?!
Try:
echo 'This is a test 12335 and 669384 535xy4' | sed 's/[^0-9]*//g'
Oh, thanks! That’s what I was looking for!
Hi!
I’m doing this:
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 ?
you can use \b instead of [^0-9], \b means word boundary in regexp
sed -i “s/…/…/g” file
replaces the contents of file