开发者

awk/sed for test command

from my ksh I have

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

can I get s开发者_JS百科uggestion how to verify the same without echo command? ( maybe awk/sed is fine for this? )

lidia


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.


read ign val && [ X$val != XSOME_WORD ] && echo "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.


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.?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜