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
Extracting a string from one file and searching the same string in other files mohancrr Shell Programming and Scripting 1 09-19-2007 04:17 AM
grep - searching for a specific string manthasirisha Shell Programming and Scripting 2 01-05-2006 09:24 AM
searching text files on specific columns for duplicates Gerry405 UNIX for Dummies Questions & Answers 2 08-18-2005 11:51 AM
Searching for data on a specific line numbers rkumar28 Shell Programming and Scripting 8 06-18-2005 01:34 AM
Searching for a specific phrase on Unix server mmcaleer UNIX for Dummies Questions & Answers 1 02-07-2005 04:18 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 03-11-2002
dinplant dinplant is offline
Registered User
  
 

Join Date: Jun 2001
Posts: 6
Question Searching for a specific string in an argument

I want to check the second argument for a specific string .

The code below is what I am trying, but I get:

UX:test (./test): ERROR: { if ($0 ~ /StringImLooking4/) {print $1} }: Unknown operator


I want to test if the second argument contains the string StringImLooking4

Unixware 7

code:

#!/bin/sh
echo $2 > /tmp/temp1
if [ /usr/bin/awk '{ if ($0 ~ /StringImLooking4/) {print $1} }' /tmp/temp1 ]; then

cp -p *.log \SAVE
rm /tmp/temp1
fi

Last edited by dinplant; 03-11-2002 at 03:03 PM..
  #2 (permalink)  
Old 03-11-2002
Jimbo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
If expr finds the desired string, it will test true:


Code:
if expr "$2" : ".*StringImLooking4" > /dev/null ; then
   echo 'its there'
fi

Or you could test the output of expr, which will be length of the located string. Note that I have to enclose this nested command within back-quotes:


Code:
if [ `expr "$2" : ".*StringImLookingFor"` -gt 0 ] ; then
   echo 'its there'
fi

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:42 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