The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Can IBM Simplify Complex Event Processing? iBot Complex Event Processing RSS News 0 04-09-2008 08:10 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 03:06 AM
a script to simplify the use of grep kemobyte Shell Programming and Scripting 2 05-01-2007 01:57 PM
Howto Simplify Multiple Exports in .bash_profile monkfan Shell Programming and Scripting 1 03-30-2006 07:49 AM
Howto Simplify/Factorize Exports in .bash_profile monkfan UNIX for Dummies Questions & Answers 1 03-29-2006 11:59 PM

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 08-08-2007
sudhish sudhish is offline
Registered User
  
 

Join Date: Jun 2007
Location: India, Kerala
Posts: 10
How can I simplify the script

Hi all,

How can I simplify following script,
Logic is to find two strings (strings are case sensitive) from a file.

if [ `grep -x "$1" "$path"/Hostname/$file_name|wc -l` -eq 1 ]; then
if [`grep -x "$2" "$path"/Hostname/$file_name|wc -l` -eq 1 ]; then
Group=`echo $1_hostname`
fi
fi

Please help me on this.

Regards
Sudhish s. kumar
  #2 (permalink)  
Old 08-08-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
You can do something like

Code:
grep -x "$1" "$path"/Hostname/$file_name >/dev/null 2>&1
rtn1_val=$?
grep -x "$2" "$path"/Hostname/$file_name >/dev/null 2>&1
rtn2_val=$?

if [[ $rtn1_val -eq 0 && $rtn2_val -eq 0 ]]
then
        Group=`echo $1_hostname`
fi
  #3 (permalink)  
Old 08-08-2007
bigearsbilly bigearsbilly is offline
Registered User
  
 

Join Date: Feb 2006
Location: Southern England
Posts: 104
grep -e "($1|$2)"
  #4 (permalink)  
Old 08-09-2007
sudhish sudhish is offline
Registered User
  
 

Join Date: Jun 2007
Location: India, Kerala
Posts: 10
Quote:
Originally Posted by bigearsbilly View Post
grep -e "($1|$2)"
grep -e "(string1|string2)" /filename

This command is not working

In fact I was looking for some thing like you suggested

Thanks
Regards
Sudhish S. Kumar
  #5 (permalink)  
Old 08-09-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
So are you trying to match either of the strings in your file, or do you want both of the strings to be present.
  #6 (permalink)  
Old 08-09-2007
FOOGLE FOOGLE is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
try
/usr/xpg4/bin/grep -e 'string1|string2'
  #7 (permalink)  
Old 08-09-2007
waiq waiq is offline
Registered User
  
 

Join Date: Aug 2007
Location: Sweden, Växjö
Posts: 3
I think you need to escape the "|".. So grep -e "string1\|string2" filename should work.
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 03:46 PM.


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