Searching String from set of similar File pattern from the Dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching String from set of similar File pattern from the Dir
# 1  
Old 09-20-2010
Question Searching String from set of similar File pattern from the Dir

Guys,

Here is the script that searches string from the set of similar files from the log directory, All the file patterns are defined as input file, from where the script should map to those files in the LOG_DIR and should start searching the strings from all those similar files.

Code:
#!/bin/bash
#
#

# Script name without path

BASENAME=${0##*/}

#Default Config & Log Path

myLocation=/home/user1
myInst=${HOME}/config/application.lst
myLog="/logs/production/application/log"
myString="${HOME}/config/string

#Main Script

echo "Please, enter log file name pattern for SEARCH: "

#File Transformation

read -r $myInst

if [ ! -f "${myLog}" ]
then
        echo "Invalid log file. It does not exist."
        exit 1
fi

#Searching the Pattern

for ${myInst} in ${myLog}
do
        echo "searching for the search pattern in the file $myInst"
        while read mLine
        do
                echo "Searching for the line :-- $mLine"
                egrep '' "${mLine}"'' "${myInst}"
        done <<EOF > "${myString}"
done

And the content of the $myInst is something like this

Code:
cat ${HOME}/config/application.lst

### INSTANCE###            ## FILE_NAMES ##


Customer_Choice =                         "Customer_Choice_Log1
                                                       Customer_Choice_Log2
                                                       Customer_Choice_Log3
                                                       Customer_Choice_Log4
                                                       Customer_Choice_Log5"

Add_AccountService =                      "Add_AccountService_Log1
                                                           Add_AccountService_Log2
                                                           Add_AccountService_Log3
                                                           Add_AccountService_Log4
                                                           Add_AccountService_Log5"

EquipmentHistory =                          "EquipmentHistory_Log1
                                                         EquipmentHistory_Log2
                                                         EquipmentHistory_Log3
                                                         EquipmentHistory_Log4
                                                         EquipmentHistory_Log5"

ApplIicationError =            "ApplIicationError_Log1
                                           ApplIicationError_Log2
                                           ApplIicationError_Log3
                                           ApplIicationError_Log4
                                           ApplIicationError_Log5"

ManagementService =                        "ManagementService_Log1
                                                           ManagementService_Log2
                                                           ManagementService_Log3
                                                           ManagementService_Log4
                                                           ManagementService_Log5"

ESSService =             "ESSService_Log1
                                   ESSService_Log2
                                   ESSService_Log3
                                   ESSService_Log4
                                   ESSService_Log5"

Information_Service =                  "Information_Service_Log1
                                                     Information_Service_Log2
                                                     Information_Service_Log3
                                                     Information_Service_Log4
                                                     Information_Service_Log5"

ResoucreIntegration =        "ResoucreIntegration_Log1
                                           ResoucreIntegration_Log2
                                           ResoucreIntegration_Log3
                                           ResoucreIntegration_Log4
                                           ResoucreIntegration_Log5"

Loggertrans =            "Loggertrans_Log1
                                  Loggertrans_Log2
                                  Loggertrans_Log3
                                  Loggertrans_Log4
                                  Loggertrans_Log5"

Message_Outgoing =        "Message_Outgoing_Log1
                                          Message_Outgoing_Log2
                                          Message_Outgoing_Log3
                                          Message_Outgoing_Log4
                                          Message_Outgoing_Log5"

Message_Incoming =        "Message_Incoming_Log1
                                          Message_Incoming_Log2
                                          Message_Incoming_Log3
                                          Message_Incoming_Log4
                                          Message_Incoming_Log5"

But getting this error, can someone let me know , where should i correct this script.

Code:
"xmlsearch.sh" 41 lines, 719 characters
$ bash -x xmlsearch.sh
+ BASENAME=xmlsearch.sh
+ myLocation=/home/user1
+ myInst=/home/user1/config/application.lst
+ myLog=/logs/production/application/log
xmlsearch.sh: line 39: unexpected EOF while looking for matching `"'
xmlsearch.sh: line 42: syntax error: unexpected end of file


Last edited by raghunsi; 09-20-2010 at 04:24 AM.. Reason: Changing the Tag name for more responsed
# 2  
Old 09-20-2010
Quote:
Originally Posted by raghunsi
Code:
#!/bin/bash
(...)
myLog="/logs/production/application/log"
myString="${HOME}/config/string"

#Main Script
(...)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[SOLVED] Replace a string in nextline after searching a pattern

Hi, I have a requirement where I need to replace a string in a line and this line will be identified by search criteria on previous line: E.g.: I have an xml file and Contents as below: <Root> <NameValue> <name>Global/Text/Data</name> <value>This is valid... (14 Replies)
Discussion started by: mailing2vamsi
14 Replies

2. Shell Programming and Scripting

Searching a particular string pattern in 10000 files

Problem Statement:- I need to search a particular `String Pattern` in around `10000 files` and find the records which contains that `particular pattern`. I can use `grep` here, but it is taking lots of time. Below is the command I am using to search a `particular string pattern` after... (3 Replies)
Discussion started by: raihan26
3 Replies

3. UNIX for Dummies Questions & Answers

merge lines within a file that start with a similar pattern

Hello! i have a text file.. which contains the data as follows i want to merge the declarations lines pertaining to one datatype in to a single line as follows i've searched the forum for help.. but couldn't find much help.. how can i do this?? (1 Reply)
Discussion started by: a_ba
1 Replies

4. Shell Programming and Scripting

Searching set of string from Live Running Logs

Hey just need one simple syntax to search for the string from the Live Running Logs. The strings are placed in a $infile & everytime the script should pull each string from $infile and should provide as an input for grepping from Live running logs on a rotational basis. So here are the Contents... (14 Replies)
Discussion started by: raghunsi
14 Replies

5. Shell Programming and Scripting

Searching a pattern in a file.

Hi Guys, I am writing a shell script to extract only the error message from a log file. I am having difficulty in searching the highlighted text in the below code. <runtimeinfo datetime="Sun Apr 04 20:02:52 EDT 2008" docid="" source="RAWDATA" event="ERROR"... (2 Replies)
Discussion started by: prash1986
2 Replies

6. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

7. UNIX for Dummies Questions & Answers

Searching for files with certain string pattern

Hello All I would like to search for files containing certain string pattern under all the directories under /vobs/vobname and print the output to a file in my home directory. How can I do this? Note: /vobs/vobname conatins several directories. Thank You in advance newbetounix (1 Reply)
Discussion started by: intrigue
1 Replies

8. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

9. UNIX for Dummies Questions & Answers

Searching list of entries in file for actual files in dir

Hi all, I have a file entries.txt that contains a number of entries all on seperate lines e.g. test1 test2 test3 test4 Then in a directory called /TestFiles I have a number of files that could contain the above text in the file name e.g. qwertytest1.csv qwertytest2.csv... (2 Replies)
Discussion started by: not4google
2 Replies

10. Shell Programming and Scripting

from dos dir a: to similar to a dds tape?

is it possible to see what is in a dds tape? like in dos, we can write dir a: to see the contents of it? thanks PS : actually, i came from a DOS background. so most of the time, i will try to relate unix to dos. of course, dos never came close to unix. but unix is like many instances of dos... (3 Replies)
Discussion started by: yls177
3 Replies
Login or Register to Ask a Question