Home > Archive > AWK > July 2006 > formatting a file with columnar values into matrix
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
formatting a file with columnar values into matrix
|
|
| Vidhya 2006-07-10, 7:55 am |
| Dear all,
I have a binary file like this:
P3
# CREATOR: The GIMP's PNM Filter Version 1.0
2048 1536
255
255
255
255
255
255
255
255
255
..
..
..
..
..
upto 2048 * 1536 values. I need to convert them to row * columns of
2048 * 1536.
How do I go abt with this?
Pl. help
Vidhya
| |
| Juergen Kahrs 2006-07-10, 7:55 am |
| Vidhya wrote:
> I have a binary file like this:
>
> P3
> # CREATOR: The GIMP's PNM Filter Version 1.0
> 2048 1536
> 255
This looks like a PPM file, the ASCII flavour, not the binary.
> upto 2048 * 1536 values. I need to convert them to row * columns of
> 2048 * 1536.
>
> How do I go abt with this?
Use the proper tool:
http://netpbm.sourceforge.net/doc/pamflip.html
| |
| Vidhya 2006-07-10, 7:56 am |
| Hai Juergen,
I am not interested in rotating the file, but formatting a single
columnar data into a matrix of 2048 * 1536 rows and columns which i
want to further process to obtain a parameter out of the values.
So help!
| |
| Juergen Kahrs 2006-07-10, 7:56 am |
| Vidhya wrote:
> I am not interested in rotating the file, but formatting a single
> columnar data into a matrix of 2048 * 1536 rows and columns which i
> want to further process to obtain a parameter out of the values.
OK, but it is really unusual that someone has PPM files
with pixels in a single column. I guess something else
has gone wrong in preparation of the file.
Anyway, if you know that you want to put exactly
2048 contiguous input lines into one output line,
then you can do it like this:
{ printf("%d ", $1) }
((NR - offset) % 2048) == 0 {print ""}
The first line builds up a long line.
The second line inserts a line break after 2048 pixels.
The offset may be useful to skip the header.
| |
| Vidhya 2006-07-10, 6:56 pm |
| Hai Juergen
Many thanks for the code.
It worked, but the small change I required was to divided them by
columns.
Thank you once again.
Vidhya
Juergen Kahrs wrote:
> Vidhya wrote:
>
>
> OK, but it is really unusual that someone has PPM files
> with pixels in a single column. I guess something else
> has gone wrong in preparation of the file.
>
> Anyway, if you know that you want to put exactly
> 2048 contiguous input lines into one output line,
> then you can do it like this:
>
> { printf("%d ", $1) }
> ((NR - offset) % 2048) == 0 {print ""}
>
> The first line builds up a long line.
> The second line inserts a line break after 2048 pixels.
> The offset may be useful to skip the header.
|
|
|
|
|