单线posix命令以bash中的小写字符串

发布于 2025-01-25 13:36:12 字数 506 浏览 2 评论 0原文

问题

我有这个com:

sed $((SS - default_scripts))!d customScripts.txt

它给了我foo bar

我想将其转换为小写

尝试尝试

当我尝试使用|的尝试时 awk'{print tolower($ 0)}'命令什么也没返回:

$($(sed $((SS - default_scripts))!d customScripts.txt) | awk '{print tolower($0)}')

最终

请在我的错字上启发我,或向我推荐另一种以紧凑的方式将整个字符串转换为小写的方法。谢谢你!

Problem

I have this comand:

sed $((SS - default_scripts))!d customScripts.txt

and it gives me Foo Bar.

I want to convert this to lowercase.

Attempt

When I tried using the | awk '{print tolower($0)}' command on it it returned nothing:

$($(sed $((SS - default_scripts))!d customScripts.txt) | awk '{print tolower($0)}')

Final

Please enlighten me on my typo, or recommend me another POSIX way of converting a whole string to lowercase in a compact manner. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝影如岚 2025-02-01 13:36:13

您的错别字将所有内容包装在$(...)中,因此首先尝试执行sed part的输出,然后尝试执行sed ... |尴尬... 管道。

当您使用尴尬时,您不需要SED命令或Shell算术操作。如果我理解您要使用此操作:

$(sed $((SS - default_scripts))!d customScripts.txt) | awk '{print tolower($0)}'

正确地是这个尴尬命令:

awk -v s="$SS" -v d="$default_scripts" 'BEGIN{n=s-d} NR==n{print tolower($0); exit}' customScripts.txt

Your typo was wrapping everything in $(...) and so first trying to execute the output of just the sed part and then trying to execute the output of the sed ... | awk ... pipeline.

You don't need sed commands nor shell arithmetic operations when you're using awk. If I understand what you're trying to do with this:

$(sed $((SS - default_scripts))!d customScripts.txt) | awk '{print tolower($0)}'

correctly then it'd be just this awk command:

awk -v s="$SS" -v d="$default_scripts" 'BEGIN{n=s-d} NR==n{print tolower($0); exit}' customScripts.txt
大姐,你呐 2025-02-01 13:36:12

尴尬的管道应与sed替换在同一命令中,以便处理sed的输出。

$(sed $((SS - default_scripts))!d customScripts.txt | awk '{print tolower($0)}')

您不需要围绕他们俩的其他命令替换。

The pipe to awk should be inside the same command substitution as sed, so that it processes the output of sed.

$(sed $((SS - default_scripts))!d customScripts.txt | awk '{print tolower($0)}')

You don't need another command substitution around both of them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文