awk/sed 用于测试命令

发布于 2024-09-16 15:38:18 字数 210 浏览 8 评论 0原文

从我的 ksh 中,

  [[  ` echo $READ_LINE | awk '{print $2}' ` != SOME_WORD  ]] && print "not match"

我可以获得如何在没有 echo 命令的情况下验证相同内容的建议吗? (也许 awk/sed 适合这个?)

lidia

from my ksh I have

  [[  ` echo $READ_LINE | awk '{print $2}' ` != SOME_WORD  ]] && print "not match"

can I get suggestion how to verify the same without echo command? ( maybe awk/sed is fine for this? )

lidia

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

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

发布评论

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

评论(4

转瞬即逝 2024-09-23 15:38:27

如果您使用的是 ksh,那么只需使用 shell 而不必调用外部命令

set -- $READ_LINE
case "$2" in
  "SOME_WORD" ) echo "found";;
esac

为什么您仍在解决这个问题,因为我看到您有其他与此类似的线程。

if you are using ksh, then just use the shell without having to call external commands

set -- $READ_LINE
case "$2" in
  "SOME_WORD" ) echo "found";;
esac

Why are you still tacking this problem since I see you have other threads similar to this.?

眼眸印温柔 2024-09-23 15:38:25
read ign val && [ X$val != XSOME_WORD ] && echo "not match"
read ign val && [ X$val != XSOME_WORD ] && echo "not match"
想你的星星会说话 2024-09-23 15:38:25

这将按单词分割行并测试第二个单词。

var=($READ_LINE)
[[  ${var[1]} != SOME_WORD  ]] && print "not match"

你想要实现什么目标?你的几个问题几乎是相同的。

This splits the line by words and tests the second word.

var=($READ_LINE)
[[  ${var[1]} != SOME_WORD  ]] && print "not match"

What is it you're trying to accomplish? Several of your questions are nearly identical.

巷雨优美回忆 2024-09-23 15:38:23

像这样的东西会起作用:

awk -v x="$READ_LINE" -v y="SOME_WORD" 'BEGIN { split(x, a); if (a[2] != y) print "not match";}'

但是 $READ_LINE 从哪里来?你想实现什么目标?可能还有一个很好的普通 shksh 解决方案。

我非常怀疑您的说法:echo(可能是 shell 内置函数)比 awk 花费更多时间。这是一个 plain sh 版本:

set -- $READ_LINE
[ x$2 != xSOME_WORD] && echo "not match" 

但是 ksh 丹尼斯·威廉姆森的解决方案看起来最适合您的情况。

Something like this will work:

awk -v x="$READ_LINE" -v y="SOME_WORD" 'BEGIN { split(x, a); if (a[2] != y) print "not match";}'

But where does $READ_LINE come from? What are you trying to accomplish? There might just also is a good plain sh or ksh solution.

I highly doubt your claim that echo (which might be a shell builtin) takes more time than awk. Here is a plain sh version:

set -- $READ_LINE
[ x$2 != xSOME_WORD] && echo "not match" 

But the ksh solution of Dennis Williamson looks the best for your situation.

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