tags:

views:

54

answers:

4

hi

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

A: 

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.

schot
the target is to save time (echo take time awk not)
lidia
A: 
read ign val && [ X$val != XSOME_WORD ] && echo "not match"
reinierpost
A: 

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.

Dennis Williamson
var=($READ_LINE) isnt valid syntax in ksh!
lidia
yes it is. you must be using very old ksh
ghostdog74
@lidia: What version of ksh? Are you using `#!/bin/ksh`, `#!/usr/bin/ksh` or `#!/bin/sh` as the first line of your script (the shebang)?
Dennis Williamson
A: 

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

ghostdog74

related questions