AWK在模式上将文件拆分为较小的文件 [英] AWK split files into smaller files on pattern

查看:62
本文介绍了AWK在模式上将文件拆分为较小的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于以下文件:

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>

我正在使用:

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

要遍历文件文件夹,请将它们拆分为仅包含一个"ISA"数据集的文件.我想保留原始源文件名,并在末尾添加1,例如subfile1,subfile2,subfile3.我都做到了.

To loop through a folder of files, splitting them into files containing one "ISA" data set only. I want to keep the original source file name and add 1 to the end like subfile1, subfile2, subfile3. I have accomplished both.

我将如何定义一个输出目录,子文件"将进入该目录,将原始源文件保留在原始位置,而子文件目录"中仅包含子文件".

How would I define an output directory, where the "subfiles" would go, leaving the original source file in the original location, and only having the "subfiles" in the "subfile directory".

我陷入了种种死胡同,并寻求紧急帮助.

I have run into a variety of dead ends and am asking for help as a last resort.

提前谢谢!

推荐答案

在文件名之前添加目录名称:

Add the directory name before the filename:

print > "subfiles/"file

如果在Windows上,则应使用反斜杠\分隔目录,如下所示:

If you are on windows, you should use the backslash \ to separate the directory, like this:

print > "subfiles\\"file

(反斜杠应转义)

这假定目录已经存在.另外,在使用awk时,请使用单引号,例如awk 'commands'文件

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

这篇关于AWK在模式上将文件拆分为较小的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆