我需要打印名称中包含“/”的行之间的行。我尝试过:
awk '/+SOLUTION/ESTIMATES/,/-SOLUTION/ESTIMATES/' $F > fil$F
和
awk '/+SOLUTION"/"ESTIMATES/,/-SOLUTION"/"ESTIMATES/' $F > fil$F
和
awk '/"{+SOLUTION/ESTIMATES}"/,/"{-SOLUTION/ESTIMATES}"/' $F > fil$F
但错误总是或多或少与“未终止的字符串”相同。
如何打印这些图案之间的线条?
通过替换
/
模式\57
之间的记录(以及具有这些模式的记录)可以被打印。但请在使用范围表达式之前阅读本文。
/regex/
是 的缩写$0 ~ /regex/
,您也可以编写$0 ~ "regex"
,因此除了通过在其前面加上前缀或与字符值一起使用(在基于 ASCII 的系统上,例如在基于 EBCDIC 的系统上)来转义 之外/
\
,您还可以执行以下操作:\octal
/
\57
\141
注意
+
是扩展的正则表达式运算符,因此需要转义为\+
或[+]
。由于\
在 的语法中也有特殊含义"strings"
,因此最好将其加倍,以便\
将 a 传递给正则表达式引擎。通过某些awk
实现,您可以侥幸逃脱,"\+"
但不是全部。Note that using redirection rather than passing the file path as argument is preferable when possible as
awk
would choke on values of$F
such as-
or that contain=
(or that start with-
with older versions of busyboxawk
). You also forgot to quote that$F
argument making it subject to split+glob. Quoting parameter expansions in targets of redirections is generally not needed except for the notable exceptions of ksh88 and the bash shell when not POSIX mode (the latter still widely used) so it's still a good habit to quote them there as well.Here, instead of a regex match, you could do a substring search:
To print from the line that is exactly
+SOLUTION/ESTIMATES
to the one that is exactly-SOLUTION/ESTIMATES
(or to the end of the input if not found):Using
perl
gives more flexibility:当在 awk正则表达式常量中使用时,必须对正斜杠字符进行转义以将其与周围的分隔符区分开。以 GNU awk 为例:
但
此外,该
+
字符在 awk 使用的扩展正则表达式 (ERE) 方言中具有特殊含义,如果您想匹配文字加字符,则应对其进行转义。所以: