Convert lines into columns
Solved
Dan_NB
Posted messages
9
Status
Member
-
Dan_NB Posted messages 9 Status Member -
Dan_NB Posted messages 9 Status Member -
Hello, I’d like to know how to convert lines into columns in a text file? (for an import into gnuplot)
example: x 1 2
y 12 13
would become:
x y
1 12
2 13
note: the two lines x and y are quite large, and I’m wondering if that could be a problem. Indeed, with the command:
paste <(head -1 nn| tr -s ' ' '\n') <(tail -1 nn| tr -s ' ' '\n')
I do get columns but the x column is offset compared to the y column.
Thanks in advance!
example: x 1 2
y 12 13
would become:
x y
1 12
2 13
note: the two lines x and y are quite large, and I’m wondering if that could be a problem. Indeed, with the command:
paste <(head -1 nn| tr -s ' ' '\n') <(tail -1 nn| tr -s ' ' '\n')
I do get columns but the x column is offset compared to the y column.
Thanks in advance!
1 answer
Hi,
The problem is that we need concrete examples and not approximations.
In fact your so-called 2 lines are eight;-(
Taking as reference your example given on Developpez
;-((
I edited the file "brol" (in fic) with a "sed" command and the solution you gave works really well:
--
Zen my nuggets ;-)
Faites un geste pour l'environnement, fermez vos fenêtres et adoptez un manchot.
The problem is that we need concrete examples and not approximations.
In fact your so-called 2 lines are eight;-(
Taking as reference your example given on Developpez
$ cat -n brol 1 0 1E-20 39.6 79.2 118.9 158.5 198.1 237.8 277.4 317.0 2 385.7 421.4 457.1 492.8 528.5 564.2 599.9 635.6 671.3 3 723.1 759.9 796.7 833.5 870.4 907.2 944.0 980.8 1017.6 4 1079.9 1116.2 1152.5 1188.8 1225.1 1261.4 1297.7 1334.0 1370.3 5 4.705E+03 4.705E+03 4.698E+03 4.691E+03 4.684E+03 4.677E+03 4.670E+03 4.663E+03 4.656E+03 4.648E+03 6 4.643E+03 4.637E+03 4.631E+03 4.625E+03 4.619E+03 4.613E+03 4.607E+03 4.600E+03 4.594E+03 7 4.587E+03 4.581E+03 4.574E+03 4.568E+03 4.561E+03 4.554E+03 4.547E+03 4.540E+03 4.533E+03 8 4.527E+03 4.521E+03 4.515E+03 4.509E+03 4.503E+03 4.497E+03 4.491E+03 4.485E+03 4.479E+03 $ wc -l < brol 8
;-((
I edited the file "brol" (in fic) with a "sed" command and the solution you gave works really well:
$ paste <(head -1 fic| tr -s ' ' '\n') <(tail -1 fic| tr -s ' ' '\n') 0 4.705E+03 1E-20 4.705E+03 39.6 4.698E+03 79.2 4.691E+03 118.9 4.684E+03 158.5 4.677E+03 198.1 4.670E+03 237.8 4.663E+03 277.4 4.656E+03 317.0 4.648E+03 385.7 4.643E+03 421.4 4.637E+03 457.1 4.631E+03 492.8 4.625E+03 528.5 4.619E+03 564.2 4.613E+03 599.9 4.607E+03 635.6 4.600E+03 671.3 4.594E+03 723.1 4.587E+03 759.9 4.581E+03 796.7 4.574E+03 833.5 4.568E+03 870.4 4.561E+03 907.2 4.554E+03 944.0 4.547E+03 980.8 4.540E+03 1017.6 4.533E+03 1079.9 4.527E+03 1116.2 4.521E+03 1152.5 4.515E+03 1188.8 4.509E+03 1225.1 4.503E+03 1261.4 4.497E+03 1297.7 4.491E+03 1334.0 4.485E+03 1370.3 4.479E+03
--
Zen my nuggets ;-)
Faites un geste pour l'environnement, fermez vos fenêtres et adoptez un manchot.
thank you for the response. As for the number of lines, I actually used a script sell whose goal is to put all the lines of my document after the 1st or 2nd line and therefore theoretically I manage to get 2 lines. Here is the shell script in question:
Could I ask you for the modification that you made using the shell command to obtain 2 lines please?