For Programmers: Free Programming Magazines  


Home > Archive > AWK > June 2004 > move records into their own data files









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 move records into their own data files
Joseph Paish

2004-06-12, 3:55 pm

i have managed to create a file that will contain all records for each widget in a large data file
using the following command :

cat /file/of/unique/widget/names | awk '{print "touch $0" /path/to/data/files/"$0".dat"}' | bash

i now have about 80 different filenames, one for each widget.

now what i need to do is read the data file and based on the value in the 4th field, write that
record to the appropriate file.

an example of a record is : 12/23/2002 bought 1000 widget1 23.49

i want to write this record to the file /path/to/data/files/widget1.dat, and do the same thing with
each of the other records in the data file.

this is what i have come up with so far (it doesn't work).

cat /path/to/all/records | awk '{print >> "/path/to/data/files""$4"."dat"}'

i don't get any error messages, but the individual data files are empty.

am i even on the right track?

thanks

joe
Charles Demas

2004-06-12, 3:55 pm

In article <zsDyc.1203$0A.9354@localhost>,
Joseph Paish <jpaish@freenet.edmonton.ab.ca> wrote:
>i have managed to create a file that will contain all records for each
>widget in a large data file
>using the following command :
>
>cat /file/of/unique/widget/names | awk '{print "touch $0"
>/path/to/data/files/"$0".dat"}' | bash
>
>i now have about 80 different filenames, one for each widget.
>
>now what i need to do is read the data file and based on the value in
>the 4th field, write that
>record to the appropriate file.
>
>an example of a record is : 12/23/2002 bought 1000 widget1 23.49
>
>i want to write this record to the file /path/to/data/files/widget1.dat,
>and do the same thing with
>each of the other records in the data file.
>
>this is what i have come up with so far (it doesn't work).
>
>cat /path/to/all/records | awk '{print >> "/path/to/data/files""$4"."dat"}'
>
>i don't get any error messages, but the individual data files are empty.
>
>am i even on the right track?
>
>thanks
>
>joe


try this:

cat /path/to/all/records |
awk '{file="/path/to/data/files/" $4 ".dat"
print >> file
close(file)}'


Chuck Demas

--
Eat Healthy | _ _ | Nothing would be done at all,
Stay Fit | @ @ | If a man waited to do it so well,
Die Anyway | v | That no one could find fault with it.
demas@theworld.com | \___/ | http://world.std.com/~cpd
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com