How to check a string conating a search word or not ...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check a string conating a search word or not ...
# 1  
Old 01-27-2007
How to check a string conating a search word or not ...

Hi fiends,

I need some help.

i have a var called fname="req_detail_TAM.dat"
and is have a search string var as tmp="TAM".
Now my requirement is i need to check whether a "fname" is contains "search str" or not. if search string is part of the filename, then i need to store value 1 in a variable called "flag" else i need to assign 0 to flag.


I can i do that inside a shell script.

vi test
fname=="req_detail_TAM.dat"
tmp="TAM"
flag=`--- command --`


How can i form that command. Plz help me out.

Regards,
Manu
# 2  
Old 01-27-2007
Quote:
Originally Posted by manu.vmr
[...]
i have a var called fname="req_detail_TAM.dat"
and is have a search string var as tmp="TAM".
Now my requirement is i need to check whether a "fname" is contains "search str" or not. if search string is part of the filename, then i need to store value 1 in a variable called "flag" else i need to assign 0 to flag.
With bash:

Code:
[ "${fname/*TAM*/TAM}" = "$tmp" ] && flag="1" || flag="0"


With external commands:

Code:
[ "$(expr match "$fname" ".*${tmp}.*")" -gt 0 ] \
&& flag="1" || flag="0"

# 3  
Old 01-27-2007
With Ksh :
Code:
[[ $fname = *TAM* ]] && flag="1" || flag="0"


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

3. Shell Programming and Scripting

Search and replace the string with new word using xml tags

Hi All i need to replace the url1 inside <remote> tag in below xml in first instance and in the second instance with url2. any help appreciated <locations> <hudson.scm.SubversionSCM_-ModuleLocation> <remote>https://svn2015.com/svn/repos/internalshard</remote> ... (4 Replies)
Discussion started by: madankumar.t@hp
4 Replies

4. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

5. Shell Programming and Scripting

Search string in unix and print whole matching word

Hi I have requirement to search string starting with specific characters and print whole matching word in that string. example mystr="ATTRIBUTE NAME="Event Name" VALUE="Execute"" I want to search by passing "NAME=" and result should be NAME="Event Name". i am using below command but... (3 Replies)
Discussion started by: tmalik79
3 Replies

6. Homework & Coursework Questions

Word Search: Can you please check if this is correct. thanks!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Im currently doing a search command.. for example , when i typed a certain word , lets say "DOG".. all... (7 Replies)
Discussion started by: jenimesh19
7 Replies

7. Shell Programming and Scripting

WORD SEARCH - CHECK IF CORRECT!

Im currently working on a Script using PICO editor, the scripts purpose is : When you typed a certain "word" and press enter, All directories, Script, and any other files that contain that "word" will be displayed.. for example i typed "DOG".. all executable script, Directories, and any other... (3 Replies)
Discussion started by: jenimesh19
3 Replies

8. Shell Programming and Scripting

search-word-print-specific-string

Hi, Our input xml looks like: <doc> <str name="account_id">1111</str> <str name="prd_id">DHEP155EK</str> </doc> - <doc> <str name="account_id">6666</str> <str name="prd_id">394531662</str> </doc> - <doc> <str name="account_id">6666</str> <str... (1 Reply)
Discussion started by: Jassz
1 Replies

9. Shell Programming and Scripting

search a word and print specific string using awk

Hi, I have list of directory paths in a variable and i want to delete those dirs and if dir does not exist then search that string and get the correct path from xml file after that delete the correct directory. i tried to use grep and it prints the entire line from the search.once i get the entire... (7 Replies)
Discussion started by: dragon.1431
7 Replies

10. Shell Programming and Scripting

Search a String and display only word.

Hello Gurus, Apologies if this Q has been repeated but i was not able to find it :( I have an input file: ------------------------------- Replace DB.Employee as select column1 column2 from DB_T.Emp and DB.Test and DB.Dept and DB_T.Ter; ------------------------ (4 Replies)
Discussion started by: indrajit_u
4 Replies
Login or Register to Ask a Question