I'm trying to replaces patterns and cleanup a file containing multiple words to get one word per line.
The result is achieved using this command line:
sed -e '/^[[:space:]]*$/ d' \ # remove empty line -e 's/^[[:space:]]*//' \ # remove white space at the beginning -e 's/[[:space:]]*$//' \ # remove white space at the ending (EOL) -e 's/[[:space:]][[:space:]]*/\n/g' \ # convert blanks between words to newline -e '$a\' # add a newline if missing at EOF -e ..... # replace other patterns.
(the last expression was found in How to add a newline to the end of a file?)
The idea is to process the file (eg. replaces some pattern) and format the file at the same time with only one small sed program.
I'm sure its possible to use other sed features to reduces the expression.