Script to search a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to search a string
# 1  
Old 05-14-2013
Script to search a string

Hi all


Am having records as below
file1
----
abc
12a
a2b


am trying to write a script to identify the character is present in the specified array


validchar=a b c d e 1
rec=`cat file1`
am getting the records in loop

for i in $rec
do
if [ $i in $validchar-------how to check here in array

please help

if it is present no issues if the string is not there in validchar i need to print out
# 2  
Old 05-14-2013
check this one

Code:
 
#!/bin/sh 
for var in ` cat input_file.txt | sed 's/./&\n/g'`
do
if [ $var == "a" -o $var == "b" ] ; then
        echo " do something "
else
        echo $var                   
fi
done

# 3  
Old 05-14-2013
"a" -o $var == "b"

i want to change dynamically the array strings(validchar)
# 4  
Old 05-14-2013
Could explain how the dynamic variable are generated ? so that we do the test againt it.
Do you look for getopt , check
Code:
man getopt

for more details .
# 5  
Old 05-14-2013
Am having records as below
file1
----
abc
12a
a2b

file2
-----
a
b
c
d
e


am trying to write a script to identify the character is present in the specified array


validchar=`cat $file2`
rec=`cat file1`
am getting the records in loop

for i in $rec
do
if [ $i in $validchar-------how to check here in array

please help

if it is present no issues if the string is not there in validchar i need to print out
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep command in Linux in a script where the search string has a space

I have a file xyz with the following content PPPL 0123 PPPL 0006 POFT 0923 POFT 1111 WENT 2323 SEND 2345 I also have another file named MasterFile where it contains the above mentioned data million times with different digits at the end for example some times it contains SEND 9999 or WENT... (4 Replies)
Discussion started by: knijjar
4 Replies

2. Shell Programming and Scripting

How to Search a string in a file in shell script?

I have a text file which is generated when the batch job is run. This batch may take few mins to run. When completed, the last line of the text file would be process completed. I need a shell script which will wait for this file till the process completed is printed in it, once found, it would move... (2 Replies)
Discussion started by: Lalat
2 Replies

3. Shell Programming and Scripting

Linux shell script, search by an input string

So, there is a large file where I have to conduct several search using bash shell scripting. The file is like this: TITLE and AUTHOR ETEXT NO. Aspects of plant life; with special reference to the British flora, 56900 by Robert Lloyd... (1 Reply)
Discussion started by: Philia
1 Replies

4. Shell Programming and Scripting

Shell script to search all files for every string in another file

Hello All I have a pattern.txt file in source directory ((/project/source/) in linux server and data looks like: 123abc17 234cdf19 235ifg20 I have multiple log files in log directory (/project/log/) in linux server and data for one log file looks like: <?xml version="1.0" processid... (11 Replies)
Discussion started by: pred55
11 Replies

5. Shell Programming and Scripting

UNIX shell script to search a string in a file

Hi folks, I am new for shell script, I hope somebody to help me to write shell script My requirement is below steps 1. I have apache access.log i.e located in /var/log/httpd/ Ex. 127.0.0.1 - - "GET... (14 Replies)
Discussion started by: Chenchireddy
14 Replies

6. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

7. 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

8. Shell Programming and Scripting

Simple (not for me) string search script

hi there, I am a complete newb to bash but am going to try and make a script to help me seach text files for strings of interest, any help that one of you gurus could pass on will be greatly received!! I want to write something like: in "text1.txt" find "string1" and copy out the line... (7 Replies)
Discussion started by: jumbo999
7 Replies

9. Shell Programming and Scripting

Shell Script to Search for a particular String and copy the timestamp to a variable

Hi, We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below: Process Beginning - 08-26-2010-23.41.47 DB2 CONNECTION SUCCESSFUL! Ready to process and load file: FILENAME # of... (2 Replies)
Discussion started by: Praveenkulkarni
2 Replies

10. Shell Programming and Scripting

shell script to search a string and delete the content

Hi, I've a shell script e.g. #!/bin/bash echo "Enter the next hop id" read nhid echo "enter the IP address" read IP echo "enter the interface name" read name echo "enter the enable/disable state" read state exit 0 now from this script i want to search strings in another (.cam) ... (6 Replies)
Discussion started by: vic_mnnit
6 Replies
Login or Register to Ask a Question