Skip to main content
deleted 2 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file
 
0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Explanation

  • When processing file, we save $1 and $3 to array a with index from 0 to number of lines with each line. Then print $1 and $2.

  • In the end, we loop through array a, print each of its element (which is value $1 $3). The order is kept because we loop with index from 0 to length of array a again.

Updated

For arbitrary columns n, I use perl:

$ perl -anle '$h{$i++} = [@F[0..$#F]];
  END {
      for $j (1..$#F) {
          for (sort {$a<=>$b} keys %h) {
              print $h{$_}->[0]," ",$h{$_}->[$j]
          }
      }
  }' file

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file
 
0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Explanation

  • When processing file, we save $1 and $3 to array a with index from 0 to number of lines with each line. Then print $1 and $2.

  • In the end, we loop through array a, print each of its element (which is value $1 $3). The order is kept because we loop with index from 0 to length of array a again.

Updated

For arbitrary columns n, I use perl:

$ perl -anle '$h{$i++} = [@F[0..$#F]];
  END {
      for $j (1..$#F) {
          for (sort {$a<=>$b} keys %h) {
              print $h{$_}->[0]," ",$h{$_}->[$j]
          }
      }
  }' file

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file
0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Explanation

  • When processing file, we save $1 and $3 to array a with index from 0 to number of lines with each line. Then print $1 and $2.

  • In the end, we loop through array a, print each of its element (which is value $1 $3). The order is kept because we loop with index from 0 to length of array a again.

Updated

For arbitrary columns n, I use perl:

$ perl -anle '$h{$i++} = [@F[0..$#F]];
  END {
      for $j (1..$#F) {
          for (sort {$a<=>$b} keys %h) {
              print $h{$_}->[0]," ",$h{$_}->[$j]
          }
      }
  }' file
added 289 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file

0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Explanation

  • When processing file, we save $1 and $3 to array a with index from 0 to number of lines with each line. Then print $1 and $2.

  • In the end, we loop through array a, print each of its element (which is value $1 $3). The order is kept because we loop with index from 0 to length of array a again.

Updated

For arbitrary columns n, I use perl:

$ perl -anle '$h{$i++} = [@F[0..$#F]];
  END {
      for $j (1..$#F) {
          for (sort {$a<=>$b} keys %h) {
              print $h{$_}->[0]," ",$h{$_}->[$j]
          }
      }
  }' file

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file

0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Explanation

  • When processing file, we save $1 and $3 to array a with index from 0 to number of lines with each line. Then print $1 and $2.

  • In the end, we loop through array a, print each of its element (which is value $1 $3). The order is kept because we loop with index from 0 to length of array a again.

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file

0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Explanation

  • When processing file, we save $1 and $3 to array a with index from 0 to number of lines with each line. Then print $1 and $2.

  • In the end, we loop through array a, print each of its element (which is value $1 $3). The order is kept because we loop with index from 0 to length of array a again.

Updated

For arbitrary columns n, I use perl:

$ perl -anle '$h{$i++} = [@F[0..$#F]];
  END {
      for $j (1..$#F) {
          for (sort {$a<=>$b} keys %h) {
              print $h{$_}->[0]," ",$h{$_}->[$j]
          }
      }
  }' file
added 333 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file

0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Explanation

  • When processing file, we save $1 and $3 to array a with index from 0 to number of lines with each line. Then print $1 and $2.

  • In the end, we loop through array a, print each of its element (which is value $1 $3). The order is kept because we loop with index from 0 to length of array a again.

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file

0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Here is an awk solution:

$ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file

0 0
0.05 9.6877884e-06
0.1 4.2838688e-05
0.15 0.00016929444
0.2 0.00036426881
0.25 0.00055234582
0.3 0.00077448576
0.35 0.00082546537
0.4 0.0012371619
0.45 0.0013286382
0 0
0.05 0.0024898597
0.1 0.0049595502
0.15 0.0074092494
0.2 0.009839138
0.25 0.012249394
0.3 0.014640196
0.35 0.017011717
0.4 0.019364133
0.45 0.02169761

Explanation

  • When processing file, we save $1 and $3 to array a with index from 0 to number of lines with each line. Then print $1 and $2.

  • In the end, we loop through array a, print each of its element (which is value $1 $3). The order is kept because we loop with index from 0 to length of array a again.

Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading