bash 如何忽略 awk 命令中的转义序列警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20366589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:51:08  来源:igfitidea点击:

How to ignore the escape sequence warning in awk command

bashshellawk

提问by user2589079

I using the below command to get the line number for the specific string

我使用下面的命令来获取特定字符串的行号

str_to_search="\/searchString >"
fileName=Myfile.txt
startingCt=$(awk '
gawk '/PATTERN/ {print FNR}' filename
~ str{print NR; exit }' str="$str_to_search" $fileName) endingCt=$(($startingCt + 3)) echo $startingCt echo $endingCt

I am able to get the line numbers but i am getting the warning message for escape sequence as

我能够获得行号,但我收到了转义序列的警告消息

awk: cmd. line:1: warning: escape sequence \/' treated as plain/'

awk:cmd。第 1 行:警告:转义序列\/' treated as plain/'

Please let me know if there is any way to ignore the warnings for escape sequence and is there any better way of getting the line number. Thanks in advance.

请让我知道是否有任何方法可以忽略转义序列的警告,以及是否有更好的方法来获取行号。提前致谢。

回答by Oz123

The problem is probably related to your awk version.

问题可能与您的 awk 版本有关。

See the link here: http://ubuntuforums.org/showthread.php?t=474549

请参阅此处的链接:http: //ubuntuforums.org/showthread.php?t=474549

Here is way with AWK:

这是 AWK 的方法:

sed -n '/pattern/=' filename

May I also offer this solution, although it's not using awk?

我也可以提供这个解决方案,虽然它没有使用 awk?

##代码##

Sed and AWK kind of like cute brothers, you will find some kind of version of them on many systems, and the share a lot of features, but with different ways of using them.

sed 和 AWK 有点像可爱的兄弟,你会在很多系统上找到它们的某种版本,并且共享很多功能,但是使用它们的方式不同。

The above command will output only the line number of the pattern you are looking for.

上面的命令将只输出您正在寻找的模式的行号。