AWK splits files into smaller files by template

I have a file similar to:

ISA.00. <rest of line> information lines information lines ... ... ... ISA.00. <rest of line> information lines information lines ... ... ISA.00. <rest of line> 

I use:

 awk "/ISA.00./{file=(FILENAME)(++i)}{print > file}" %LOCATION%\%CURRFILE% 

Skip the folder with the files, dividing them into files containing only one "ISA" dataset. I want to keep the original name of the source file and add 1 to the end, for example subfile1, subfile2, subfile3. I performed both.

How can I determine the output directory where the "subfiles" will go, leaving the original source file in the original location and only having the "subfiles" in the "subfile directory".

I have come across various dead ends and ask for help as a last resort.

Thank you in advance!

+4
source share
1 answer

Add a directory name in front of the file name:

 print > "subfiles/"file 

If you are in windows, you should use the backslash \ to separate the directory, for example:

 print > "subfiles\\"file 

(backslash must be escaped)

This assumes the directory already exists. Also, use single quotes when with awk, such as awk 'commands' file

+1
source

Source: https://habr.com/ru/post/1499205/


All Articles