Awk script to re-format columns 
Author Message
 Awk script to re-format columns

Hi,

I need some help to reformat the following input:

    IQ    NUMBER
     1         8
     2         6
     3         3
     4         4
     5         1
     6         1
     7         1
     8         2

into the following output:

    IQ  1  2  3  4  5  6  7  8
NUMBER  8  6  3  4  1  1  1  2

Actually, can awk to do that? Or should I use something else.

Please respond via mail too. Thanks

Tassilo

******************************************************************

  Tassilo Krug v. Nidda
   Max-Planck-Institute for Biophysics
   Dept. of Structural Biology
  Heinrich-Hoffmann-Str. 7
  D-60528 Frankfurt / Main, Germany

  Tel:  +49-69-96769-360        Fax:  +49-69-96769-359


******************************************************************

     _/_/   _/_/_/  tassilo krug von nidda
   _/          _/  s-mail: kelsterbacher str. 44a, 60528 frankfurt

   _/_/    _/_/  www: http://www.*-*-*.com/

******************************************************************

CLICK FOR HUMAN GUIDES - CLICKFISH - NOW YOU KNOW!

http://www.*-*-*.com/

******************************************************************



Mon, 11 Aug 2003 23:41:11 GMT  
 Awk script to re-format columns

Quote:

> I need some help to reformat the following input:

>     IQ    NUMBER
>      1         8
>      2         6
>      3         3
>      4         4
>      5         1
>      6         1
>      7         1
>      8         2

> into the following output:

>     IQ  1  2  3  4  5  6  7  8
> NUMBER  8  6  3  4  1  1  1  2

> Actually, can awk to do that?

Of course. Use an associative array.

    number_by_iq[$1] = $2

Print the array using a for loop in an END rule.

Quote:
> Or should I use something else.

No.

Quote:
> Please respond via mail too.

Nope. Sorry.

--
Jim Monty

Tempe, Arizona USA



Tue, 12 Aug 2003 00:54:24 GMT  
 Awk script to re-format columns
Quote:

>I need some help to reformat the following input:

>    IQ    NUMBER
>     1         8
>     2         6
>     3         3
>     4         4
>     5         1
>     6         1
>     7         1
>     8         2

one (bad) example:

awk 'BEGIN{printf "    "}{printf "%s  ",$1;line2=line2 $2 "  "}END{print "\n" line2}' foo.bar

    IQ  1  2  3  4  5  6  7  8  
NUMBER  8  6  3  4  1  1  1  2  

 -Falk



Tue, 12 Aug 2003 02:43:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. New to FORTRAN - Reformatting One Column to Multiple Columns

2. Reformat Browse Box Columns

3. ASIS (Was Re: IrisAda) REPOST - REFORMATTED TO 80 COLUMNS

4. reformatting Fortran code with characters beyond column 72

5. sed/awk script to format a file??

6. Reformatting a table using awk

7. Creating an awk script to extract other scripts from a file

8. Access to Script Name Within Awk Script

9. Windows passes filename in 8.3 format and not in long format to tcl script

10. awk - lines to columns

11. sed/awk - grabbing column/pos help!!

12. loop thur each column using awk

 

 
Powered by phpBB® Forum Software