I have a text file of 1..n lines, each one containing at least one string between parentheses. Within each string, there is one or more strings separated by commas. I need to extract each string, thus:
You might want to add something to delete the first line of the resulting file as the tr does a great job but also translates the first bracket into a blank line before your data so you end up with an additional line.
tr -sc 'a-zA-Z' '\n' < FILE
THIS
THAT
THE
OTHER
THING
OR
MAYBE
THIS
THING
sed does the trick:
tr -sc 'a-zA-Z' '\n' < FILE|sed '1d'
THIS
THAT
THE
OTHER
THING
OR
MAYBE
THIS
THING
How does tr work? I mean, I tested it, and it clearly works. Maybe I do not understand the arguments for it. The man pages make it seem as though all it will do is replace SET1 with SET2, so how does: tr -sc 'a-zA-Z' '\n' make it just replace () and comas? Seems like it is basically replacing the opposite, (grep -v comes to mind..).
-c, -C, --complement
first complement SET1
-s, --squeeze-repeats
replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character