The UNIX and Linux Forums  


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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
storing variables in array.Please help nua7 Shell Programming and Scripting 7 07-17-2008 10:47 AM
KSH Setting multiples variables with an array wolfhurt Shell Programming and Scripting 1 05-20-2008 11:00 AM
Getting variables into a array. vivsiv Shell Programming and Scripting 2 02-06-2008 03:45 PM
grep command with combined variables in Ksh cin2000 Shell Programming and Scripting 4 02-22-2006 10:57 AM
Array variables kavitha Shell Programming and Scripting 2 03-23-2004 10:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-05-2009
prashant43's Avatar
prashant43 prashant43 is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore
Posts: 31
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..
  #2 (permalink)  
Old 01-05-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,891
Are you trying to search for the string "CENTER LEFT RIGHT"? Or are you trying to search for ONE of the three words?
  #3 (permalink)  
Old 01-05-2009
prashant43's Avatar
prashant43 prashant43 is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore
Posts: 31
CENTER LEFT RIGHT are the members of the array.

I want to search all these members in file
  #4 (permalink)  
Old 01-05-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,891
You are saying you want to find any one of them? Then:

Code:
echo ${Array[*]}| tr ' ' '\n' | fgrep -f - filename.txt

  #5 (permalink)  
Old 01-05-2009
prashant43's Avatar
prashant43 prashant43 is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore
Posts: 31
Thanks otheus
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0