text data conversion: rows into columns
I have data in the following format
1 realnumber1 2 realnumber2 3 realnumber3 4 realnumber4 5 realnumber5
6 realnumber6 7 realnumber7 8 realnumber8 9 realnumber9 10 realnumber10
I would like to convert it to:
In other words, I would like to convert each line into a column and output them one after another.
I am guessing I should be able to do this in awk, sed or fortran but I don't really know how as I am pretty new to all of them. Can anyone help me solve this problem?
You dont mention what is the actual caracter in between the numbers. So if it just a space you could do:
cat my_data_file.txt | cut -d ' ' -f "2 4 6 8 10" | sed "s/ /\n/g"
if it can have more than one space or tabs you could do:
cat my_data_file.txt | tr "\t" " " | tr -s " " | cut -d ' ' -f "2 4 6 8 10" | sed "s/ /\n/g"
In both case you get just a column with the realnumbers.
I hope this is useful, and it does what you need :)
thanks for the reply. it makes sense what you did i should have thought of it. but for some reason instead of new line i get this:
These are first five lines of my input file:
1 247.443I 2 244.457I 3 243.286I 4 242.492I 5 240.353I
6 238.872I 7 238.120I 8 237.393I 9 236.585I 10 236.320I
11 235.759I 12 235.163I 13 234.007I 14 233.297I 15 233.201I
16 232.299I 17 232.004I 18 231.424I 19 230.982I 20 230.000I
21 229.825I 22 229.417I 23 228.864I 24 228.482I 25 227.870I
Mmmm I've tried it with your data and it works fine on my system. But for what I see as your output you might have omitted the inverted slash ( \ ) in the sed command, so insted of getting a newline you are just getting an n.
The numbers are separated by single spaces right?
See if this is the problem or or or or... we'll look for another solution jajajaja
In perl the following should work
@data = `cat filename.txt`;
By the way can anyone tell me how to use code tags around here?
@ppanyam: You could have searched the site for the answer. But here's the link you are looking for:
Hope this helps.
|All times are GMT -5. The time now is 02:59 AM.|