How do i use pattern matching to remove all letters but leave numbers in sed?
-
Man page for sed: https://www.lightnetics.com/post/3334
Sample file used:
$ cat linefile This is line one 1000 This is line two 2000 This is line three
Use this: [a-Z] matching all ascii characters.
$ sed 's/[a-Z]/ /g' linefile
Result, including blank lines
1000
2000
To remove the blank line too
Use this: -e to specify expression or script. Here we used two expressions.
$ sed -e 's/[a-Z]/ /g' -e '/^\s*$/d' linefile
Result
1000
2000
© Lightnetics 2024