in reply to Splitting files on regex

What was the linux command? There is split but that's for splitting into chunks of certain line or byte size. Can you give a sample expression and file? For one liners, look at perlrun, and specifically at the -e, -n, -p, and -a flags. Here's a (WARNING -- very inefficent) quick example:
perl -ne "/foo(\d+)/ && do { open FILE, '>>', 'split'.$1.'.txt'; print + FILE $_; close FILE }" blah.txt

Replies are listed 'Best First'.
Re^2: Splitting files on regex
by swampyankee (Parson) on Nov 02, 2005 at 15:15 UTC

    {rummages through dusty portions of memory} I think the command was csplit, which would split on regex. There is probably a Windows version of it at the GnuWin32 site

    emc

Re^2: Splitting files on regex
by svenXY (Deacon) on Nov 02, 2005 at 15:12 UTC
    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

      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