Lets say "textfile" contains the following:
lorem$ipsum-is9simply the.dummy text%of-printing
and that you want to print each word on a separate line. However, words should be defined not only by spaces, but by all non-alphanumeric characters. So the results should look like:
lorem
ipsum
is9simply
the
dummy
text
of
printing
How can I accomplish this using the Bash shell?
Some notes:
This is not a homework question.
The simpler case when the words should be determined only by spaces, is easy. Just writing:
for i in `cat textfile`; do echo $i; done;
will do the trick, and return:
lorem$ipsum-is9simply the.dummy text%of-printing
For splitting words by non-alphanumeric characters I have seen solutions that use the IFS environmental variable (links below), but I would like to avoid using IFS for two reasons: 1) it would require (I think) setting the IFS to a long list of non-alphanumeric characters. 2) I find it kind of ugly.
Here are the two related Q&As I found
http://stackoverflow.com/questions/918886/split-string-based-on-delimiter-in-bash
http://stackoverflow.com/questions/1975849/split-line-into-words-in-bash