using csplit to split a file based on a regular expression to multiple files
0
votes
1
answer
300
views
I have a text file that has the contents of the example below, and I would like to split the file to multiple files.
[TXT] /path/to/[TXT]
[BAT] /path/to/[BAT]
[TXT] /path/to/blah/[TXT]
[BAT] /path/to/blah/[BAT]
So I have figured out I can use csplit
to at least partially do what I wanted to achieve.
csplit -f 'paths-' -b '%04d.txt' 'path/to/filelist.txt' '/^\[(.*)]\t/' '{*}'
However this splits to paths-0000.txt
.
I was hoping for something more like paths-txt.txt
and paths-bat.txt
.
Is there anyway I can get the regex match into the prefix match at all?
I did try things like -f 'paths-$1.txt'
and -f 'paths-\1.txt'
.
But neither of those did what I was hoping for them to do.
Asked by AeroMaxx
(227 rep)
Jul 12, 2023, 11:21 PM
Last activity: Jul 13, 2023, 04:31 AM
Last activity: Jul 13, 2023, 04:31 AM