title: Can we use shell variables in awk?
body: <p>Can we use shell variables in AWK like <code>$VAR</code> instead of <code>$1</code>, <code>$2</code>? For example:</p>
  
  <pre><code>UL=(AKHIL:AKHIL_NEW,SWATHI:SWATHI_NEW)
  
  NUSR=`echo ${UL[*]}|awk -F, '{print NF}'`
  echo $NUSR
  echo ${UL[*]}|awk -F, '{print $NUSR}'
  </code></pre>
  
  <p>Actually am an oracle DBA we get lot of import requests. I'm trying to automate it using the script. The script will find out the users in the dump and prompt for the users to which dump needs to be loaded.</p>
  
  <p>Suppose the dumps has two users <code>AKHIL</code>, <code>SWATHI</code> (there can be may users in the dump and i want to import more number of users). I want to import the dumps to new users <code>AKHIL_NEW</code> and <code>SWATHI_NEW</code>. So the input to be read some think like <code>AKHIL:AKHIL_NEW,SWATHI:SWATHI_NEW</code>.</p>
  
  <p>First, I need to find the Number of users to be created, then I need to get new users i.e. <code>AKHIL_NEW,SWATHI_NEW</code> from the input we have given. So that I can connect to the database and create the new users and then import. I'm not copying the entire code: I just copied the code from where it accepts the input users.</p>
  
  <pre><code>UL=(AKHIL:AKHIL_NEW,SWATHI:SWATHI_NEW) ## it can be many users like     USER1:USER1_NEW,USER2_USER2_NEW,USER3:USER_NEW..
  
  NUSR=`echo ${UL[*]}|awk -F, '{print NF}'` #finding  number of fields or users
  y=1
  while [ $y -le $NUSR ] ; do
      USER=`echo ${UL[*]}|awk -F, -v NUSR=$y  '{print $NUSR}' |awk -F: '{print $2}'` #getting     Users to created AKHIL_NEW and SWATHI_NEW and passing to SQLPLUS
      if [[ $USER = SCPO* ]]; then
          TBS=SCPODATA
      else
          if [[ $USER = WWF* ]]; then
              TBS=WWFDATA
          else
              if [[ $USER = STSC* ]]; then
                  TBS=SCPODATA
              else
                  if [[ $USER = CSM* ]]; then
                      TBS=CSMDATA
                  else
                      if [[ $USER = TMM* ]]; then
                          TBS=TMDATA
                      else
                          if [[ $USER = IGP* ]]; then
                          TBS=IGPDATA
                          fi
                      fi
                  fi
               fi
          fi
      fi
  
      sqlplus -s '/ as sysdba'  &lt;&lt;EOF   # CREATING the USERS in the database 
      CREATE USER $USER IDENTIFIED BY $USER  DEFAULT TABLESPACE $TBS TEMPORARY TABLESPACE TEMP QUOTA 0K on SYSTEM QUOTA UNLIMITED ON $TBS;
  
      GRANT
      CONNECT,
         CREATE TABLE,
         CREATE VIEW,
         CREATE SYNONYM,
         CREATE SEQUENCE,
         CREATE DATABASE LINK,
         RESOURCE,
         SELECT_CATALOG_ROLE
      to $USER;
      EOF 
      y=`expr $y + 1`
  done
  
  impdp sysem/manager DIRECTORY=DATA_PUMP DUMPFILE=imp.dp logfile=impdp.log SCHEMAS=AKHIL,SWATHI REMPA_SCHEMA=${UL[*]} 
  </code></pre>
  
  <p>In the last impdp command I need to get the original users in the dumps i.e AKHIL,SWATHI using the variables.</p>