繁体   English   中英

awk 无法在 windows 上打印字符串

[英]awk cannot print strings on windows

有什么我做错了吗?

这给出了 output:

echo "hello world" | awk '{ print $0 }'

这不会:

echo "" | awk '{ print "hello world" }' echo "" | awk '{ print "hello world" }'awk 'BEGIN{ print "hello world" }'也没有)

这是 windows 上的 gnu awk。

出于这个问题的目的,我想做的就是打印一个字符串。 This runs as expected on WSL/MSYS etc., but doesn't produce output when on windows (using powershell, with awk from git's linux tools and with awk installed from choco, same result. )

我在堆栈溢出上找不到有关此特定问题的任何问题,但在 windows 与 linux 上处理字符串的方式可能存在简单的区别?

请参阅打印文档,另请参阅PC using documentation ,它处理行尾但未提及字符串差异。

您需要用双引号包裹awk命令,并在引号使用^"转义所有命令内双引号:

echo "complicated output to be parsed with interesting word otherword" | awk "{ if ($0 ~ "^"".*sasquatch"^"") {print "^"" there is a sasquatch"^""} else if ($0 ~ "^"".*otherword"^"") {print "^""other word..."^""}}"

看截图:

在此处输入图像描述

暂无
暂无

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

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