0
foundflag =  awk -F" " 'FNR==NR{A[$arg1 OFS $PREVFILE];next}
!($arg1 OFS $PREVFILE in A){X++} END{if(!X){print "No diff."} 
else {print "Diff found."}} $arg1 ${PREVFILE}
echo $foundflag

here am comparing two files and want to store awk command result into some variable please help in Ksh script.

jcrshankar
  • 1,165
  • 8
  • 25
  • 45

2 Answers2

1

I think what You need is:

foundflag=`awk ....`
  • remove spaces arounf =
  • put the command into reverse quotes (``)
kestasx
  • 1,091
  • 8
  • 15
  • you right sir, i have used ' instead of `.. now its working thank u – jcrshankar Dec 15 '14 at 10:34
  • foundflag=`awk -F" " 'FNR==NR{A[$arg1 OFS $PREVFILE];next} !($arg1 OFS $PREVFILE in A){X++} END{if(!X){print "0"} else {print "1"}}' $arg1 ${PREVFILE}` whats wrong here, why the comparison not working – jcrshankar Dec 15 '14 at 11:05
  • @jcrshankar I don't catch the idea of the algorithm. As it was already mentoned in question's comments - $arg1 and $PREVFILE are inside of single quotes (probably not working as You expect). I would sugest dumping/inspecting the contents of A at the END. – kestasx Dec 15 '14 at 11:22
  • Use the $(..) for the same result. Helpful for more complex situations. – Walter A Dec 20 '14 at 23:17
1

Or use command substitution. The backticks/gravemarks have been deprecated in favor of $()

foundflag=$(awk....)

Also note where cannot be any space around the assignment operator (no space before and after)

Community
  • 1
  • 1
D3Hunter
  • 1,329
  • 10
  • 21