|
Home > Archive > Unix Shell > January 2006 > Newbie question on awk
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Newbie question on awk
|
|
| Sylvain PERCHAUD 2006-01-22, 6:10 pm |
| Hello,
I am new to shell scripting and awk and I would to know what is the best
solution to do the following thing :
Scenario :
To insert a set of values from tables from one or more database schemes
to other database schemes.
When the user type the scheme name he has two options : either he inputs
the exact scheme name either he inputs "all" (for all schemes).
My problem : when my user inputs "all" how can I exclude the source
scheme he has input from the list of target schemes ?
Today I have the list of all my schemes in one text file.
I would like to retrieve with awk all scheme names but the one described
in one variable ($SCHEME_TGT in my example).
Here is a sample of my code :
SCHEME_SRC=
while ! [ $SCHEME_SRC ]
do
read SCHEME_SRC?"Source Scheme name (or 'all') : "
done
INSTANCE_SRC=
while ! [ $INSTANCE_SRC ]
do
read INSTANCE_SRC?"Source Instance name : "
done
SCHEME_TGT=
while ! [ $SCHEME_TGT ]
do
read SCHEME_TGT?"Target Scheme name (or 'all') : "
done
INSTANCE_TGT=
while ! [ $INSTANCE_TGT ]
do
read INSTANCE_TGT?"Target Instance name : "
done
if [ "$SCHEME_SRC" = all ]
then
for SRCSCHEMENAME in `cat schemes.txt|awk '{print $1}'`
do
#some SQL statements
done
My question is how to improve the condition "cat schemes.txt|awk '{print
$1}" to be able to retrieve all scheme names but the one from variable
$SCHEME_TGT ?
Thanks for any help or suggestions.
| |
| Sylvain PERCHAUD 2006-01-22, 6:10 pm |
| Sylvain PERCHAUD <sylvain@europe-shareware.org> wrote:
> I would like to retrieve with awk all scheme names but the one described
> in one variable ($SCHEME_TGT in my example).
Sorry, I meant $SCHEME_SRC
> My question is how to improve the condition "cat schemes.txt|awk '{print
> $1}" to be able to retrieve all scheme names but the one from variable
> $SCHEME_TGT ?
Sorry, I meant $SCHEME_SRC
| |
| Ed Morton 2006-01-22, 6:10 pm |
| Sylvain PERCHAUD wrote:
> Hello,
>
>
> I am new to shell scripting and awk and I would to know what is the best
> solution to do the following thing :
>
> Scenario :
> To insert a set of values from tables from one or more database schemes
> to other database schemes.
> When the user type the scheme name he has two options : either he inputs
> the exact scheme name either he inputs "all" (for all schemes).
>
> My problem : when my user inputs "all" how can I exclude the source
> scheme he has input from the list of target schemes ?
>
> Today I have the list of all my schemes in one text file.
> I would like to retrieve with awk all scheme names but the one described
> in one variable ($SCHEME_TGT in my example).
<snip>
> if [ "$SCHEME_SRC" = all ]
> then
> for SRCSCHEMENAME in `cat schemes.txt|awk '{print $1}'`
UUOC:
for SRCSCHEMENAME in `awk '{print $1}' schemes.txt`
> do
> #some SQL statements
> done
>
>
>
> My question is how to improve the condition "cat schemes.txt|awk '{print
> $1}" to be able to retrieve all scheme names but the one from variable
> $SCHEME_TGT ?
I think this is what you want to do:
for SRCSCHEMENAME in `awk -v tgt="$SCHEME_TGT" '$1 != tgt{print $1}'
schemes.txt`
Regards,
Ed.
| |
| Bill Marcum 2006-01-22, 6:10 pm |
| On Sun, 22 Jan 2006 01:03:04 +0200, Sylvain PERCHAUD
<sylvain@europe-shareware.org> wrote:
>
> if [ "$SCHEME_SRC" = all ]
> then
> for SRCSCHEMENAME in `cat schemes.txt|awk '{print $1}'`
> do
> #some SQL statements
> done
>
>
You don't need awk here, you could do
while read SRCSCHEMENAME junk
do
case $SRCSCHEMENAME in
"$SCHEME_SRC") ;;
*)
#some SQL statements
;;
esac
done < schemes.txt
--
Those who don't understand Linux are doomed to reinvent it, poorly.
-- unidentified source
|
|
|
|
|