> I am using awk in my script, I wanted to assign data from awk to a local
> variable on the script. How would I do that.
You can't do that directly: shell variables cannot be changed by
subprocesses.
Basically you have two options:
(1) write the value to a file and read it back from there;
(2) capture stdout from the subprocess and pick the result from there.
A third alternative that's sometimes possible is to reorganize
your script so that you call shell from within awk.
You already have an idea of a way to do the latter:
Quote:> ax=`ls -al|awk '{if ($6 == '$monthname') { print $6, $7}}`
although your quotes are a bit off, what you probably mean is
ax=`ls -al|awk '{if ($6 == "'$monthname'") { print $6, $7}}'`
or simpler
ax=`ls -al|awk '$6 == "'$monthname'" { print $6, $7}'`
Quote:> I want to assign the data in $7 to the variable filedate, so it would be
> available to perform manipulations from the script, outside the awk.
After the above you'd have months and days of month in variable ax,
and you could extract the desired data from there.
You'd have the dates for every such file in there though, and the month
for each is same so it doesn't really sound useful;
a while-read loop would probably be better.
But it depends on what you are trying to achieve. Perhaps you
could explain that a bit?
--
Tapani Tarvainen