Sponsored Content
Top Forums Shell Programming and Scripting Need help using % or like option in shell script Post 302429400 by srini02 on Monday 14th of June 2010 10:50:10 AM
Old 06-14-2010
Quote:
Originally Posted by dr.house
Code:
if [ -n $( echo $a | grep '20100614' ) ]

Code:
if [[ "$a" =~ "20100614" ]]

Hi,Thanks for the speed reply.
When i tried " if [ -n $( echo $a | grep '20100614' ) ] " this one
its saying syntax error.
here is the code I used,
Code:
a=21345zef
b=21345
case $a in
    *$date*) d=MATCH;;
    *)  d=NOT A MATCH;;
esac
echo $d
if [ -n $( echo $a | grep '20100614' ) ] then 
echo 'eureka'
else
echo 'try again'
fi



---------- Post updated at 10:50 AM ---------- Previous update was at 10:47 AM ----------

Quote:
Originally Posted by alister
A couple of inexpensive, posix-compliant approaches:
Code:
#!/bin/sh
 
a=abc_20100614_12346
date=20100614
 
 
 
# One way
 
case $a in
    *$date*) echo MATCH;;
    *) echo NOT A MATCH;;
esac
 
 
 
# Another way
 
if [ "$a" != "${a#*$date}" ]; then
    echo MATCH
else
    echo NOT A MATCH
fi

Regards,
Alister
Hi Alister,
Thanks for the speed reply.
The first code worked like a charm for me.
But I tried the second one also but its saying bad substituion.
Here is the code I used
Code:
a=21345zef
b=21345
if [ "$a" != "${a#*$date}" ]; then
    echo MATCH
else
    echo NOT A MATCH
fi

Moderator's Comments:
Mod Comment Use code tags please, ty.

Last edited by zaxxon; 06-14-2010 at 12:09 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script "-a" option

Hi, I would like to know what exactly "-a" option does in the if conditional statement. I am sure, it is not doing the logical AND (&&) operation since it appears before the file. #!/bin/ksh for file in $* ; do if ] ; then basefile=`basename $file` cp $file... (2 Replies)
Discussion started by: royalibrahim
2 Replies

2. Shell Programming and Scripting

Unix Shell Script: With Menu Option

I am attempting to create a shell script with the following capaciblities: 1. Listed options to choice from 2. Use to perform awk statements 3. Print a report with the awk results My questions are 1. How do I select more than one file for option #5 and #6 2. How to I create an... (11 Replies)
Discussion started by: jroberson
11 Replies

3. Shell Programming and Scripting

sed insert option(-i) in shell script

Hi, Please tell me how to use insert option of sed in a shell script on Solaris/AIX plateform. For example I need to insert few lines on top of every file whose name starts with say "SOL_DEL". Thanx. (2 Replies)
Discussion started by: sanjay1979
2 Replies

4. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

5. Shell Programming and Scripting

Executing a batch of files within a shell script with option to refire the individual files in batch

Hello everyone. I am new to shell scripting and i am required to create a shell script, the purpose of which i will explain below. I am on a solaris server btw. Before delving into the requirements, i will give youse an overview of what is currently in place and its purpose. ... (2 Replies)
Discussion started by: goddevil
2 Replies

6. UNIX for Dummies Questions & Answers

Invalid option errors running shell script

The script below fails with the following error messages: gzip: invalid option -- 'w' Try `gzip --help' for more information. mysqldump: Got errno 32 on write cp: invalid option -- 'w' Try `cp --help' for more information. rm: invalid option -- 'w' Try `rm --help' for more information. ... (1 Reply)
Discussion started by: ANNACTION
1 Replies

7. UNIX for Dummies Questions & Answers

Executing a tar command with the --exclude option in a Debian shell script.

Hi All, I am trying to execute the following tar command with two --exclude options to suppress extract of the two directories specified. Do I need to single quote the directory paths ?? Many thanks for your help. The relevant code excerpt from the script is: cd /var/www/${SITE} ... (7 Replies)
Discussion started by: daveu7
7 Replies

8. Shell Programming and Scripting

Call one script option to other in shell script

HI Guys, My Script abc.sh 1) Checks 2) CA Scipt 3) CIA Script 0) Exit Enter Choice : Now if i select choice 2 then after finshed choice 2 wait for 40 min and run choice 3 what i can write in CA Scipt option: if then My Code : ... (3 Replies)
Discussion started by: pareshkp
3 Replies

9. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

10. Shell Programming and Scripting

Menu Driven Bash Shell Script with Default Option

Hi All, I have written a menu driven bash shell script. Current Output is as below: ------------------------------------- Main Menu ------------------------------------- Option 1 Option 2 Option 3 Option 4 Exit ===================================== Enter your... (3 Replies)
Discussion started by: kiran_j
3 Replies
All times are GMT -4. The time now is 05:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy