in reply to Re: Splitting files on regex
in thread Splitting files on regex

Hi davidrw,

I'm afraid I cannot see where this would work. If the delimiter is somewhere in a line and if multilines are possible, it does not work for me say to split a file like the following at 'abc':

1111111111111abc2222222222 33333abc333333333 444444444444abc444_ 5555abc5555555555555555 6666666666666666666 777777777abc77777777 8888888888888888888abc00000000000000

or am I doing something completely wrong here?
Regards, svenXY

Replies are listed 'Best First'.
Re^3: Splitting files on regex
by davidrw (Prior) on Nov 02, 2005 at 15:41 UTC
    can you define "split a file"? My example above would take any line with "fooN" in it and add it to the file 'splitN.txt' ... Since OP didn't specify, i assumed by "split" he meant "send certain lines to certain files" .. From your sample data it seems that by "split" you mean "create separate files for each 'column' of data". A quick & dirty (and again, WARNING, very inefficient) way for that would be:
    perl -lne "chomp; @x = split /abc/, $_; do { open FILE, '>>', 'col'.$_ +.'.txt'; print FILE $x[$_]; close FILE } for 0 .. $#x" blah.txt