#!/bin/sh
#Section: 04
#Name: Scott Deese
my_awk="awk -v var=$1 ' /$var/ { print \$2 } ' "
echo $my_awk
schemas=`$my_awk database.txt`
ive tried this many different ways and this was the last way describe by my teacher that doesnt work.
I need to pass a variable from the sh shell to awk. the variable is $1 (first cmd line argument)
he said i sould make the awk script my variable them evaluate it in the sh script.... tried that this is what i come up with
localhost ~]$ sh ir.sh dont
awk -v var=dont ' // { print $2 } '
awk: '
awk: ^ invalid char ''' in expression
i've tried my_awk="awk ' /$1/ { print \$2 } ' "
same thing happens except the shell does put the $1 value in the correct spot
but it is never evaluated because it gives me the same syntax error
I would appreciate any help
#Section: 04
#Name: Scott Deese
my_awk="awk -v var=$1 ' /$var/ { print \$2 } ' "
echo $my_awk
schemas=`$my_awk database.txt`
ive tried this many different ways and this was the last way describe by my teacher that doesnt work.
I need to pass a variable from the sh shell to awk. the variable is $1 (first cmd line argument)
he said i sould make the awk script my variable them evaluate it in the sh script.... tried that this is what i come up with
localhost ~]$ sh ir.sh dont
awk -v var=dont ' // { print $2 } '
awk: '
awk: ^ invalid char ''' in expression
i've tried my_awk="awk ' /$1/ { print \$2 } ' "
same thing happens except the shell does put the $1 value in the correct spot
but it is never evaluated because it gives me the same syntax error
I would appreciate any help