check file for presence of set of strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check file for presence of set of strings
# 1  
Old 03-07-2011
check file for presence of set of strings

hi everybody,

I need a quick help with this issue. I have configuration file in which the following set of strings must be present. I need to check it with the bash script (leading spaces are not significant). Check must be case insensitive. Can anybody help?
Code:

... any lines
<SECTION NAME="MAP">
... any lines
    <PARAMETER NAME="ForcedLocalTDP14ForGPRSCSI"
               TYPE="BOOLEAN"
               VALUE="true"
               RANGE="True|False"
               VISIBILITY="Yes"
               MODE="Dynamic"
 ... any lines


Last edited by Franklin52; 03-07-2011 at 07:40 AM.. Reason: Please use code tags, thank you
# 2  
Old 03-07-2011
I would say
Code:
man grep

More specifically something like this:
Code:
grep -E "SECTION|PARAMETER" filename
exitStatus=$?
[ $exitStatus -eq 0 ] && echo "found"
[ $exitStatus -eq 1 ] && echo "not found"
[ $exitStatus -eq 2 ] && echo "grep error"

# 3  
Old 03-07-2011
No, this is not what I need. I know of course to grep file and check the presence of specific string. But in the config file there are many parameters which have type/value/range/visibility defined. So what I need is to parse the config file and check if parameter "ForcedLocalTDP14ForGPRSCSI" has defined its parameters as specified above (i.e. the VALUE=true and also the other pars. belong to the mentioned parameter) and if it is defined in the section "MAP" (check the order of appearance would be enough).
# 4  
Old 03-07-2011
If your file is a true xml you can use xsltproc and a xslt stylesheet to do your task.
Or you can elaborate a regular expression to match your need.

The more information you give, the easier it will be to help you ;o)
# 5  
Old 03-08-2011
OK, I needed something like this

sed -n '/<SECTION NAME=.MAP.>/,/<\/SECTION>/p' config_file.txt | sed -n '/<PARAMETER NAME=.ForcedLocalTDP14ForGPRSCSI./,/RESPONSIBILITY/p' > TDP14.cfg;
test `grep -i 'VALUE=.true.' TDP14.cfg | wc -l` -eq 1 ;
test `grep -i 'VISIBILITY=.Yes.' TDP14.cfg | wc -l` -eq 1 ;
test `grep -i 'MODE=.Dynamic.' TDP14.cfg | wc -l` -eq 1 ;
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file presence and delete other file

Hello, I have file all_file.txt at the end of process this file all_file.txt should be deleted only if there is no file present in dir /all_file/tmp/ or in it's sub directory. can you please help me with the peace of code for this. Thanks (2 Replies)
Discussion started by: kumar30213
2 Replies

2. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

3. Shell Programming and Scripting

Check presence of trigger file

Hi, I make a sftp connection successfully.My requirement is the script shall execute only after i find a trigger file(dailyreport.OK.psv) in the remote dir. If the trigger file is not present ,the script should exit else it should continue with the rest of the scripts statements. Below code is... (13 Replies)
Discussion started by: samrat dutta
13 Replies

4. UNIX for Dummies Questions & Answers

Any tricks on excluding a set of strings from a file?

Hi, Test file below: $: cat file1 DATE TIME COL1 COL2 COL3 COL4 ID 01/10/2013 0800 100 200 300 401 112 01/31/2013 1000 201 123 345 456 107 03/05/2013 1100 150 789 311 789 109 02/15/2013 1500 199 456 234 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

5. UNIX for Dummies Questions & Answers

How to check if file contains valid strings?

Hi All, I am a newbie...I would like to have a function which ll check if a file contains valid strings before "=" operator. Just to give you my requirement: assume my file has content: hello= gsdgsd sfdsg sgdsg sgdgdg world= gggg hhhh iiiii xxxx= pppp ppppp pppp my... (5 Replies)
Discussion started by: rtagarra
5 Replies

6. Shell Programming and Scripting

Check the presence of file >size?

Hi, Following script work fine: #!/bin/bash FILE=$1 if ; then echo Yay else echo Boo fi But I would like to add another condition that if FILE... (3 Replies)
Discussion started by: nrjrasaxena
3 Replies

7. OS X (Apple)

command to check presence of volume

Hi: I'm not really a programmer, but I've created a small logout hook script to copy some specific directories to a server volume when a user logs out (10.6.4). These is a laptop user, so I'm looking find: 1) the command to check if the volume (including path to directory?) is available. ... (1 Reply)
Discussion started by: kevinmmac
1 Replies

8. Shell Programming and Scripting

check presence of input file

My script is taking a file "input.in" as input for running the script. My worry is that i need to execute the script only if the file is present, if it's not don't perform the next commands. Just to have a check at the beginning of the script : If "input.in" exists, then go on. If it's does not... (4 Replies)
Discussion started by: newpromo
4 Replies

9. Shell Programming and Scripting

extracting a set of strings from a text file

i have textfiles that contain a series of lines that look like this: string0 .................................................... column3a column4a string1**384y0439 ..................................... column3b column4b... (2 Replies)
Discussion started by: Deanne
2 Replies
Login or Register to Ask a Question