splitting a record into multiple lines 
Author Message
 splitting a record into multiple lines

I would like to split records in a file into evenly spaced records and
preferably group them by a control fields. So far I have got them evenly
spaced using printf but don't know how to group the records. I think it
requires a loop may be.

awk -F| '{printf "%-10s %-10s %-20s %-5s %-5s", $1, $2, $3, $4, $5}'
filename

Thanks,

Ihtesham

raw data:

aaaa|name|address|citystate|zip
bbbb|name|address|citystate|zip
cccc|name|address|citystate|zip
aaaa|name|address|citystate|zip
dddd|name|address|citystate|zip
bbbb|name|address|citystate|zip

formated data:

aaaa
        name    address citystate       zip
        name    address citystate       zip
bbbb
        name    address citystate       zip
        name    address citystate       zip
cccc
        name    address citystate       zip
dddd
        name    address citystate       zip



Mon, 29 Oct 2001 03:00:00 GMT  
 splitting a record into multiple lines


Quote:
>I would like to split records in a file into evenly spaced records and
>preferably group them by a control fields. So far I have got them evenly
>spaced using printf but don't know how to group the records. I think it
>requires a loop may be.

What platform?

Quote:
>aaaa|name|address|citystate|zip
>bbbb|name|address|citystate|zip
>cccc|name|address|citystate|zip
>aaaa|name|address|citystate|zip
>dddd|name|address|citystate|zip
>bbbb|name|address|citystate|zip

>formated data:

>aaaa
>    name    address citystate       zip
>    name    address citystate       zip
>bbbb
>    name    address citystate       zip
>    name    address citystate       zip

Assuming Unix, you probably want to use sort as a pre-filter.
Then, you can do something like:

        #!/bin/sh
        sort < file |
        gawk '-F|' '$1 != old { print old=$1 }
        { printf("%-10s %-10s %-20s %-5s %-5s\n","",$2,$3,$4,$5) }' > filename

Note that you will probably want to play with this a bit and fiddle
with the sort settings/options.  sort varies a bit from Unix to Unix,
especially if you are using GNU tools.  In particular, you may have to
set an option to get a so-called "stable" sort.



Mon, 29 Oct 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Join multiple lines of records to single line

2. Multiple lines per record

3. how to split each new line into a list, considering quoted new line characters

4. Sorting multiple-line data to single line data

5. splitting a very large file based on characters in a record (performance)

6. Splitting app into multiple DLLs

7. Splitting app into multiple DLLs

8. splitting 1D data into multiple columns in excel

9. multiple viewports - split screen and insets

10. Splitting 'and' conditions into multiple conditions

11. Split Screen - Multiple Camera Views?

12. Split class definition across multiple files

 

 
Powered by phpBB® Forum Software