簡體   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