简体   繁体   English

整个文件中的awk分隔符

[英]awk delimiter in whole file

Input file is like this: 输入文件是这样的:

Scene  
some  
text  
...  
Scene  
some  
more  
text

And i want to be able to print the text between each 'Scene' (by printing $0, $1, etc.. like a cut -d -f would do). 而且我希望能够在每个“场景”之间打印文本(通过打印$ 0,$ 1等。就像cut -d -f一样)。
I tried a lot of things using awk but i don't understand how to make it work. 我用awk尝试了很多东西,但是我不知道如何使它工作。
awk -F '^Scene' '{print $1}' file prints the whole file, awk -F '^Scene' '{print $1}' file打印整个文件,
awk '/^Scène/{ print $1 } file' prints all the Scene it finds in the file. awk '/^Scène/{ print $1 } file'打印在文件中找到的所有Scene
i think i fail to understand the logic with awk. 我认为我无法理解awk的逻辑。

Using gnu awk you can set a custom record separator: 使用gnu awk可以设置自定义记录分隔符:

awk -v RS='Scene[[:space:]]*' 'NF' file

some
text
...


some
more
text
  • -v RS='Scene[[:space:]]*' will set input record separator as Scene followed by optional white-spaces. -v RS='Scene[[:space:]]*'将输入记录分隔符设置为Scene后跟可选的空白。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM