Sample Header Ad - 728x90

Split file into specific output filenames by pattern match

1 vote
2 answers
151 views
I have a file with this content: # new file text in file 1 # new file text in file 2 # new file text in file 3 The pattern here is # new file. I instead of saving each file to xx00, xx01 and xx02, save to specific files: another file, file new, last one. The 3 files exist in current directory, so I want to provide them as array, overwrite them: csplit -z infile '/# new file/' "${array[*]}" The array can be provided directly array=('another file' 'file new' 'last one') echo ${array[*]} another file file new last one Or list current directory array=($(find . -type f)) echo ${array[*]} ./another file ./file new ./last one A modification of this script could be the solution: awk -v file="1" -v occur="2" ' { print > (file".txt") } /^\$\$\$\$$/{ count++ if(count%occur==0){ if(file){ close(file".txt") ++file } } } ' Input_file
Asked by Smeterlink (295 rep)
Dec 12, 2023, 06:47 AM
Last activity: Dec 13, 2023, 11:14 AM