Linux Bash : Remove only numbers or patterns from a long list using SED and more

Q: I want to remove only numbers/specific patterns from a long list ?

You can use "sed" for the above task. Below is the command.

#cat filename | sed 's|[0-9]||g'
Or if you want to KEEP ONLY numbers.

# cat filename | sed 's|[^0-9]||g'

Or anything you wish to skip in whole text. for eg "-" and "." in below example

#cat filename | sed 's|[-.-]||g'

A more BASH specific way can be ,if you do not wish to use sed:

while read line; do \
    echo ${line//[0-9]/}; \
done < filename

Well only grep can also perform same stuff:

#cat test | grep -o '[^0-9-]*'

Hope you this little tricks helpful.

Enhanced by Zemanta

Popular posts from this blog

Grsecurity: Configure RHEL5/6 Kernel for Grsecurity

How to check Perl Module version in Linux

Linux Command line tips and Bash stuff