tags:

views:

403

answers:

2

Hello I have this file.csv :

coordinate1,coordinate2,value1
11111,a1,65
11111,a2,32
22222,b1,39
22222,b3,55
33333,c5,12
33333,c9,16
coordinate1,coordinate2,value2
54656,a1,65
21342,a2,32
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
568568,c5,12
568568,c9,16
coordinate1,coordinate2,value3
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
11111,a1,65
11111,a2,32
22222,b1,39
22222,b3,55
33333,c5,12
33333,c9,16

Now I would like to split this file in 3 files , everyone whit only bloc of data

Es: 1° file
   coordinate1,coordinate2,value1
    11111,a1,65
    11111,a2,32
    22222,b1,39
    22222,b3,55
    33333,c5,12
    33333,c9,16

Es: 2° file
    coordinate1,coordinate2,value2
    54656,a1,65
    21342,a2,32
    23543,b1,39
    123123,b3,55
    568568,c5,12
    568568,c9,16
    123123,b3,55
    568568,c5,12
    568568,c9,16
+1  A: 

Blatantly stolen from this forum:

awk '/YOUR_TEXT_HERE/{n++}{print >"out" n ".txt" }' final.txt

should do the trick (replacing YOUR_TEXT_HERE, of course).

Replacing it with your conditions, and sending output to #file.txt with an input file of a.txt:

$ awk '/coordinate1,coordinate2,value?/{n++}{print > n "file.txt" }' a.txt
$ ls
1file.txt  2file.txt  3file.txt  a.txt
$ cat 1file.txt 
coordinate1,coordinate2,value1
11111,a1,65
11111,a2,32
22222,b1,39
22222,b3,55
33333,c5,12
33333,c9,16
$ cat 2file.txt 
coordinate1,coordinate2,value2
54656,a1,65
21342,a2,32
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
568568,c5,12
568568,c9,16
$ cat 3file.txt 
coordinate1,coordinate2,value3
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
23543,b1,39
123123,b3,55
568568,c5,12
568568,c9,16
123123,b3,55
11111,a1,65
11111,a2,32
22222,b1,39
22222,b3,55
33333,c5,12
33333,c9,16
Mark Rushakoff
A: 

mythical Mark!! it runs ok!

I still have a need... any files created (nfile.txt) should have the following name value1.txt value3.txt value3.txt

my 'value' really it's datetime so: coordinate1,coordinate2,200911260100

...result... 200911260100.txt 200911260200.txt .... etc etc etc

how to?

gairlo
???????????????????????????
gairlo
Gairlo, this should either be a new question, or a comment on the previous answer.
Oddthinking