![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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.. |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|