Closed ferreum closed 10 years ago
:+1: Good stuff, thank you!
Hold on. It looks like this changed behavior.
I can't see anything different here, what did you notice?
echo "a b-c" | tr -s '[:space:]' '\n' | sed -e 'p;s/[^a-zA-Z0-9_]\+/\n/g'
produces
a
a
b-c
b-c
instead of
a
a
b-c
b c
How about this?
echo "a b-c " | sed -e 'p;s/[^a-zA-Z0-9_]/ /g' | tr -s '[:space:]' '\n'
produces
a
b-c
a
b
c
I'll prepare a commit. Let me know if you see any downside of the switched order of sed
and tr
.
For me, both commands produce the same lines in different order. I guess it depends on the version of sed. It's safer to tr afterwards.
Oh that's interesting. For the record I'm using BSD sed
because I'm on Mac OS.
Alright, should be good now. Thanks again!
fmt is an unclean way to split words, tr does this nicely.