I'm looking for a regexp to remove one character words. I don't mind whether using perl, awk, sed or bash built-ins.
Test case:
$ echo "a b c d e f g h ijkl m n opqrst u v" | $COMMAND
Desired output:
ijkl opqrst
What I've tried so far:
$ echo "a b c d e f g h ijkl m n opqrst u v" | sed 's/ . //g'
acegijkln opqrstv
I'm guessing that:
a isn't removed because there is no white space before itc remains because once the b has been removed, there is no more whitespace before itAttempt #2:
$ echo "a b c d e f g h ijkl m n opqrst u v" | sed 's/\w.\w//g'
s v
Here I don't get at all what's happening.
Any help + explanations are welcome, I want to learn.
You have to use word boundary \b (or) \< and \> respectively match the empty string at the beginning and end of a word.
echo "a b c d e f g h ijkl m n opqrst u v" | sed 's/\b\w\b \?//g'
(OR)
echo "a b c d e f g h ijkl m n opqrst u v" | sed 's/\<.\> \?//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