Apologies if this has been asked before, but I searched and was not able to find an answer. It's probably a simple question to answer for those of you with some experience, though...
I have a relatively long string where tokens are separated by the colon (':') character. Let's say the string is stored in a file, 'longString.txt'. The string may look something like this:
I want to separate each token with a line break instead of a colon, so that long strings are easy to read for humans. How do I do this easily from a (bash) shell command line?
I tried with tr and sed, but even if I get to replace ':' with '\n', the '\n' is apparently not interpreted as a line break in the resulting output. Sed example:
but it only works with one of the three awk binaries installed on my system (I don't have control over what is actually installed).
Could this have something to do with for example the version of sed and tr I am using (I'm not sure which version that is)? Or my environment settings (nothing special there I think)? I'm running Solaris 10 and the Bash shell in a networked environment. Some other results:
Yes, the last sed command you posted with double quotes worked fine. But sed replacements using \n as line break don't work.
It turns out that the default sed and tr on my system are probably quite old, since /usr/ucb was before /usr/bin and /bin in my PATH. When using a different tr, \n as replacement worked. When using the default (/usr/ucb/tr), it only works if the replacement is \012 instead of \n. However, \012 won't work at all with sed. I don't quite understand this - perhaps it is the result of a bad combination of tr (or sed) version and type/version of shell?
Is there a way to get sed and/or tr to print which version it is?