Hi friends,
I have data in flat file as following, first filed is the customer number. We have almost 50-100 customers in the system
100 ABC A123
100 BVC D234
100 BNC N324
200 CBC A122
200 AVC D294
200 HNC N324
300 GBC A173
300 FVC D234
300 DNC N344
I want to split the file and create individual file for each customer with customer number in the file name as follows,
File Name : 100.<TimeStamp>.txt
100 ABC A123
100 BVC D234
100 BNC N324
File Name : 200.<TimeStamp>.txt
200 CBC A122
200 AVC D294
200 HNC N324
File Name : 300.<TimeStamp>.txt
300 GBC A173
300 FVC D234
300 DNC N344
I really apprciate if anyone can help me writing this script.
This is one line with awk...
$ ls
data
$
$
$
$
$
$ cat data
100 ABC A123
100 BVC D234
100 BNC N324
200 CBC A122
200 AVC D294
200 HNC N324
300 GBC A173
300 FVC D234
300 DNC N344
$ awk -v timestamp=whatever '{print $0 >> ($1timestamp".txt")}' data
$ ls
100whatever.txt 200whatever.txt 300whatever.txt data
$ cat 100whatever.txt
100 ABC A123
100 BVC D234
100 BNC N324
$
jaduks
March 2, 2008, 2:18am
3
$ awk '{print > $1".ts.txt"}' cus.out
wow thanks Perderabo it worked like a charm!!! but it is creating one more extra file also i.e, whatever.txt. I dont want this file. I really appreciate ur input.
39 Mar 2 05:42 100whatever.txt
39 Mar 2 05:42 200whatever.txt
39 Mar 2 05:42 300whatever.txt
2 Mar 2 05:42 whatever.txt
THanks
Monica
monicasgupta:
wow thanks Perderabo it worked like a charm!!! but it is creating one more extra file also i.e, whatever.txt. I dont want this file. I really appreciate ur input.
39 Mar 2 05:42 100whatever.txt
39 Mar 2 05:42 200whatever.txt
39 Mar 2 05:42 300whatever.txt
2 Mar 2 05:42 whatever.txt
THanks
Monica
you must have some blank lines. You can ignore blank line by checking if the number of fields is non-zero....
awk -v timestamp=whatever 'NF {print $0 >> ($1timestamp".txt")}' data
And you're supposed to replace "whatever" with your timestamp.
Thanks Perderabo, it worked really fine, i really appreciate if you can be more helpful to me
once the file r created i need to do following two things.
1) Following file are created with data.
100whatever.txt
100 ABC A123
100 BVC D234
100 BNC N324
100whatever.txt
200 CBC A122
200 AVC D294
200 HNC N324
100whatever.txt
300 GBC A173
300 FVC D234
300 DNC N344
Now I want to remove first record from all the file, should look like
100whatever.txt
ABC A123
BVC D234
BNC N324
100whatever.txt
CBC A122
AVC D294
HNC N324
100whatever.txt
GBC A173
FVC D234
DNC N344
2) Zip all the files into one file as WHATEVER.zip
THanks
MOnica