I've tried almost everything (I guess) but nothing worked. (Operating System: Ubuntu 12.04)
Expressions to be matched (removed from text files):
a c 4
a k 23
o s 1
What I tried:
's/[[a-z][:space:][a-z][:space:][0-9]]\{1,\}//gi'
's/.\s.\s[0-9]+//g'
's/[:alpha:][:space:][:alpha:][:space:][:digit:]+'
This should match:
sed 's/[a-z][ ]*[a-z][ ]*[0-9]*//gi'
Your 1st try misses a couple of square brackets, and you don't need the outermost one:
sed 's/[a-z][[:space:]][a-z][[:space:]][0-9]\{1,\}//gi' input
Your 2nd example fails because you need to escape the +
, and still it will only work in gnu sed:
sed 's/.\s.\s[0-9]\+//g' input
Also some similar problems with the last one:
sed 's/[[:alpha:]][[:space:]][[:alpha:]][[:space:]][[:digit:]]\+//' input
The one in the middle is close! You have to escape the plus sign for a reason that is beyond me.
I also replaced the dot ".
" with "[a-z]
" so it only matches letters.
sed 's/[a-z]\s[a-z]\s[0-9]\+//g'
Bonus portable version for older sed
-Versions (Hello, Mac users!). Some sed
implementations are picky on the "+
" :
sed 's/[a-z]\s[a-z]\s[0-9][0-9]*//g'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With