in Education by
I am reading some equipment configuration output and check if the configuration is correct, according to the HW configuration. The template configurations are stored as files with all the params, and the lines contain regular expressions (basically just to account for variable number of spaces between "object", "param" and "value" in the output, also some index variance) First of all, I cannot use grep -f $template $output, since I have to process each line of the template separately. I have something like this running while read line do attempt=`grep -E "$line" $file` # ...etc done < $template Which works just fine if the template doesn't contain regex. Problem: grep interpretes the search option literally when these are read form file. I tested the regex themselves, they work fine from the command line. With this background, the question is: How to read regex from a file (line by line) and have grep not interprete them literally? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Using the following script: #!/usr/bin/env bash # multi-grep regexes="$1" file="$2" while IFS= read -r rx ; do result="$(grep -E "$rx" "$file")" grep -q -E "$rx" "$file" && printf 'Look ma, a match: %s!\n' "$result" done < "$regexes" And files with the following contents: $ cat regexes RbsLocalCell=S.C1.+eulMaxOwnUuLoad.+100 $ cat data RbsLocalCell=S1C1 eulMaxOwnUuLoad 100 I get this result: $ ./multi-grep regexes data Look ma, a match: RbsLocalCell=S1C1 eulMaxOwnUuLoad 100! This works for different spacing as well $ cat data RbsLocalCell=S1C1 eulMaxOwnUuLoad 100 $ ./multi-grep regexes data Look ma, a match: RbsLocalCell=S1C1 eulMaxOwnUuLoad 100! Seems okay to me.

Related questions

0 votes
    I am reading some equipment configuration output and check if the configuration is correct, according to the ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I need to replace each character of a regular expression, once evaluated, with each character plus the @ ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I need to replace each character of a regular expression, once evaluated, with each character plus the @ ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'd like to use svn delete to delete all files start by src\main\webapp\styles\images\outline in ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    In a database the file is contained in ________ (a) Entire database (b) Two area (c) One area ... from Multiple Granularity in portion Concurrency Control of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    _______ mechanisms ensure that information contained in objects does not flow explicitly or implicitly into less protected ... Inference control (2)Access control (3)Flow control...
asked Jun 1, 2021 in Technology by JackTerrance
0 votes
    I have this log file that I'm currently trying to parse. Jan 12 2019, 14:51:23, 117, 10.0 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    Which of the following is not a class of java.util.regex? (a) Pattern class (b) matcher class (c) ... Regular Expressions of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    Which of the following is not a class of java.util.regex? (a) Pattern class (b) matcher class (c ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    Eleven bags of wheat flour, each marked 5 kg, actually contained the following weights of flour (in kg.) 4.97 5. ... 5 kg of flour. Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    12 packets of salt, each marked 2kg, actually contained the following weights (in kg) of salt: 1.950, 2.020, ... than 2kg of salt? Select the correct answer from above options...
asked Nov 23, 2021 in Education by JackTerrance
0 votes
0 votes
    Which of the following is contained in NumPy library? (a) n-dimensional array object (b) tools for ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    Which of these literals can be contained in float data type variable? (a) -1.7e+308 (b) -3.4e ... java programming questions and answers pdf, java interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
...