Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

So I have a bunch of text files which look like this:

T1
r1 a b c d
r2 d e f g
...

T2
r1 h i j k
r2 l m n o
...

And I want to make FOUR different text files in the following format:

__ T1 T2 ...
r1 a h ...
r2 d l ...

__ T1 T2 ...
r1 b i ...
r2 e m ...

So basically, I have a certain number of files. Each picks a TEMPERATURE and then runs over MAGNETIC FIELDs (T1... temp; r1,r2,.. magnetic field) and then the a,b,c,d etc are 4 different calculations, each column being its own. I want to be able to compile the FIRST column for each T (file) into a single file so I can copy it into excel, then compile the SECOND column for each T into a different file and do the same. If someone tells me how to put in the data so that it formats it exactly like my files I can detail my question more...

share|improve this question
    
I want to make it where it is in the format to be plotted as a surface for each column (magnetic fields (r1,..) down the side, then the column FOR THAT CALCULATION, going across for each T value; I'm not sure if that helps explain it better or not... –  malevolence19 Oct 22 '12 at 0:16
add comment

closed as too localized by warl0ck, Renan, manatwork, Mat, rahmu Oct 22 '12 at 18:50

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

I'm assuming T1, T2 are the names of four input files:

Using awk:

awk 'FNR==1 { header = header " " FILENAME;
              next # we want to skip the first line
            }
            { rows[$1]; for(i=2;i<=NF;i++) A[$1,i] = A[$1,i] " " $i }
        END { for(i=2;i<=5;i++) {
                printf("__%s\n", header);
                for(j in rows) printf("%s%s\n", j, A[j,i]);
              }
            }' T1 T2 T3 T4 

This only creates a single output file, with all your desired tables concatenated. If you want to split it into four files, you'll have to do more work.

If you want to extract the header lines from the first line rather than the name of the input files, replace FILENAME with $0.

share|improve this answer
    
I'm sorry, I'm somewhat unfamiliar with using terminal/things like this. T1, T2 are actually the first line, or I was going to format the data to have an output like this: > T1 r1 a b c d // > T1 r2 e f g h Also, when I try to run that commmand I get an error: "awk: cmd. line:5: for(j in rows) printf("%s%s\n", j, A[j,i] awk: cmd. line:5: ^ unexpected newline or end of string" If I have the files in the above format is there a way to accomplish this? –  malevolence19 Oct 22 '12 at 14:14
    
Can someone tell me how to input the data from my actual output file so it keeps its original spacing and everything? If I had that I could show you how I wanted it to come out and it might be easier to understand. Thank you guys! –  malevolence19 Oct 22 '12 at 15:07
    
Keeping original spacing is difficult with awk. It's possible but tends to be more complicated. There was a ) missing in my code. I replaced it. And also adjusted code to skip first line in each of the four input files. –  dubiousjim Oct 22 '12 at 19:31
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.