The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-05-2009
prashant43's Avatar
prashant43 prashant43 is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore
Posts: 27
Lightbulb How to use variables/array in grep command

Hi,

I have a reqmt as i have some values in array and I want to search each value in a file by grep command.
Here goes my scripting:

#!/bin/ksh
set -A ArrayA CENTER LEFT RIGHT
echo "ArrayA contains: ${ArrayAİ*¨}"
grep -e "${ArrayAİ*¨}" filename.txt


The above grep is working for me.
If I want to search a value from a variable in array, it is FAILING.
EG:

#!/bin/ksh
set -A ArrayA CENTER LEFT RIGHT
set -A Filenamearray filename1.txt filename2.txt
grep -e "${ArrayAİ1¨}" ${Filenamearrayİ*¨}

The above grep is NOT WORKING.

Can any one please let me know how to search values in array by using grep command.

Regards
Prashant

Last edited by prashant43; 01-05-2009 at 09:19 AM..