[英]escaping backslash and bracket on windows awk
I have an awk
command that I want to use on cmd
. 我有一个要在
cmd
上使用的awk
命令。 The following command works well in bash
, but fails on windows cmd
: 以下命令在
bash
运行良好,但在Windows cmd
上失败:
echo errr | awk '/err/ { $0 = "\033[32m" $0 "\033[39m" }; 1'
I get the following error on windows: 我在Windows上收到以下错误:
awk: cmd. line:1: '/err/
awk: cmd. line:1: ^ invalid char ''' in expression
After going through some questions, I changed my command to: 经过一些问题后,我将命令更改为:
echo errr | awk "/err/ { $0 = "\033[32m" $0 "\033[39m" }; 1"
but that gives me: 但这给了我:
awk: cmd. line:1: /err/ { $0 = \033[32m $0 \033[39m }; 1
awk: cmd. line:1: ^ backslash not last character on line
awk: cmd. line:1: /err/ { $0 = \033[32m $0 \033[39m }; 1
awk: cmd. line:1: ^ syntax error
How can I port my command to work in cmd
? 如何移植命令以在
cmd
工作?
Standard advice when running awk on Windows: 在Windows上运行awk时的标准建议:
a) don't do it, install cygwin and run awk from there instead a)不要这样做,安装cygwin并从那里运行awk
b) if "a" is not possible then create a file "foo.awk", store your script /err/ { $0 = "\\033[32m" $0 "\\033[39m" }; 1
b)如果不可能使用“ a”,则创建一个文件“ foo.awk”,存储您的脚本
/err/ { $0 = "\\033[32m" $0 "\\033[39m" }; 1
/err/ { $0 = "\\033[32m" $0 "\\033[39m" }; 1
in that, and then run it as awk -f foo.awk
to avoid Windows nightmarish quoting rules. /err/ { $0 = "\\033[32m" $0 "\\033[39m" }; 1
,然后以awk -f foo.awk
身份运行它,以避免Windows噩梦般的引用规则。
instead of awk 'your commands' use awk -e 'your commands', there should be no error. 而不是awk'您的命令'使用awk -e'您的命令',应该没有错误。 I do not have windows to check.
我没有窗户要检查。 Will it be coloring the text?
它会给文本着色吗? Read my comment below your question.
在您的问题下方阅读我的评论。
EDIT: OK, now if you have version 6 in PowerShell, it should work coloring like this: 编辑:确定,现在,如果您在PowerShell中具有版本6,则它应该像这样进行着色:
echo errr | awk -e "/err/ { $0 = '`e[32m' $0 '`e[39m'}; 1 "
If you have a different version windows, look for the correct escape sequence in the link I provided. 如果您使用其他版本的窗口,请在我提供的链接中查找正确的转义序列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.