If the goal is to display the output from the backticks, then the backticks and the echo are of course needless. But to actually capture the output from the awk script into a variable, that's how you do it. Now let's turn to how to mix shell and awk variables.
You can mix shell and awk by playing around with quotes. Most often, you need quoting in order to pass the awk script to awk as a single string (unless of course your script is so simple that it's a single token, from the shell's point of view) and conventionally, we use single quotes to prevent the shell from messing with the string's contents. But if you do want the shell to, say, place the value of its first argument inside the string, then you can do that by relaxing the quoting.
The tricky quoting there is a closing single quote, followed by $1 in double quotes, followed by an opening single quote. Inside the awk script, all of this is in another set of double quotes, to mark it as a string in awk. The "seesaw quoting" causes the shell to interpolate the value of $1 smack dab into the middle of the awk script. So if the value of the shell's variable $1 is "shell", then the awk interpreter will end up executing the following script:
So the awk script is pieced together from three parts: $1 == " (in single quotes) followed by the value of the shell variable $1 (in double quotes), followed by " { print $2} (in single quotes).
Some newer awk interpreters allow you to avoid this tricky quoting by using the -v switch, but the original, ancient awk didn't have that.
Here, the awk variable var is assigned on the command line to the value of the shell variable $1.
I am using a variable called $variable in a pattern search to print from a starting variable to a constant value. the variable search should be case in sensitive.
i tired using Ip at the end in the below command. but in ksh it is not working.
sed -n "/$variable/,/constant/p" file
i also... (11 Replies)
My goal is to create a script that will check if in a test or production environment. I wrote this script to check $host variable to check which server I'm on but this script does not work.
if
then
BASE=/home/fmtest; export BASE
else
BASE=/home/fmprod; export BASE
fi
... (5 Replies)
From a shell script I'm trying to remove the first two files of whats returned from the head -2 command so I tried piping it to xargs rm -f but I can't get it to work.
How do I remove the files from the head command?
ls -al *clit* *servr* |sort -t_ -nk2 | head -2 |xargs rm -f (3 Replies)
Anyone know how to check a filename that contains a date and compare whiich file is older using a ksh shell script? The filename looks like aaaaa_20110615 (1 Reply)
Guys,
I am new in awk , I face problem while i try to use for loop in awk,
I am using ksh, i am trying to set a for loop which runs as man times as the records in a file , the for loop like for(a=1;a<=5;a++) is working in my awk script but the one i need is not working :wall:
for example
... (8 Replies)
Hi
newbeeeee alarm
i want to send a little script over ssh
this script mus download a report.tar then rename and move. the report name format is report_<host.with.dot>-10-09-20-11:55:25.tar
function remote_cmd_mv
{
_host=$1
ARCHROOTDIR='/tmp'
... (8 Replies)
I am using /usr/bin/ksh in AIX
I am reading the values of $dbname, $dbatmpdir/dbdir.$$, and $scope from a different file
All I have to do is check if $dbname exists in file $dbatmpdir/dbdir.$$ and
$scope should have a value either 'TABLE' or 'SCHEMA'.
When I execute the following code. I am... (3 Replies)