Transforming columns into lines
It is endemic for most Linux tools to work with lines, but not with columns (sed, awk, grep, etc..).
However, it may happens,that you have a file where the data should be read in columns.
Example
$ cat in.txt2008-09-21|2008-09-22|2008-09-23
Sunday|Monday|Tuesday
Solution
Here below is how to convert this file into a 3-lines format (date|day)
$ split -l1 in.txt tmp_
$ sed -i 's/|/\x0A/g' tmp_
$ paste -d'|' tmp_* >out.txt
$ rm -f tmp_*
$ cat out.txt
2008-09-21|Sunday
2008-09-22|Monday
2008-09-23|Tuesday
Check out the manual to understand these 2 commands:split and paste.
Limitations
This script will only work with a limited number of lines, (input : less than 676). This is due to suffix added by the split command which by default includes only 2 characters, but if necessary the -a option can be used to increase that limit.
For the sed (according to the versions used), two problems may arise:
The
-i option requires a suffix (
. bak, or another) in this case, be careful to change the
paste command to take into account the files generated by
split and not by
sed (tmp_? eg) commands
If the version does not support octal notation
\ 012 or hexadecimal
\X0A: Press backslash, then following two combinations <Ctrl+V> <Ctrl+J> (or press enter key), then complete the order and to quit the sequence.