dimanche 16 avril 2017

cut one file into multiple files based on certain dynamic pattern and return with the same dynamic pattern as the output file name

Suppose I have the following content in one file: (Music.txt)

artist name 2010.01.01

Katy Perry feat. Snoop Dogg California Gurls

Usher feat. will.i.am OMG

B.o.B feat. Hayley Williams Airplanes

artist name 2010.02.02

Katy Perry feat. Snoop Dogg California Gurls

Usher feat. will.i.am OMG

artist name 2010.03.03

Katy Perry feat. Snoop Dogg California Gurls

......

Should generate the following files with the file name of a dynamic pattern:

Output file1: artist name 2010.01.01.txt

*Katy Perry feat. Snoop Dogg California Gurls

Usher feat. will.i.am OMG

B.o.B feat. Hayley Williams Airplanes*

Output file2: artist name 2010.02.02.txt

Katy Perry feat. Snoop Dogg California Gurls

Usher feat. will.i.am OMG

Output file3: artist name 2010.03.03.txt

Katy Perry feat. Snoop Dogg California Gurls

A very similar solution in python is already given here: Split one file into multiple files based on pattern (cut can occur within lines). However, it's not dynamic. Thank you for any hint!

Aucun commentaire:

Enregistrer un commentaire