Why RegEx Matching is NOT Working in My Bash Script?

Why RegEx Matching is NOT Working in My Bash Script?

Content Index :

Why RegEx Matching is NOT Working in My Bash Script?
Tag : regex , By : orneka
Date : November 29 2020, 04:01 AM

hope this fix your issue The problem is that you're quoting the regex which takes away all the special regex powers: only quote the literal bits, particularly if they are spaces. The 2nd problem is that you're using a for loop to read the file: don't do that
while IFS= read -r CD; do
    if [[ "$CD" =~ ([[:alpha:][:blank:]]*)"- "([[:digit:]]*)" - "(.*) ]]
        echo "Found ${BASH_REMATCH[2]}"
done < soundtrack.txt

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

bash script regex matching

Tag : regex , By : Debashree
Date : March 29 2020, 07:55 AM
I wish did fix the issue. In my bash script, I have an array of filenames like
xbraer@NO01601 ~
$ VAR=`echo "site_hello.xml" | sed -e 's/.*_\(.*\)\.xml/\1/g'`

xbraer@NO01601 ~
$ echo $VAR

xbraer@NO01601 ~

How to check if files matching a regex exist in a directory in bash script?

Tag : linux , By : kakashi_
Date : March 29 2020, 07:55 AM
may help you . srv_*.log is not a regex but a glob matcher.
You can just capture the output and redirect stderr to /dev/null:
FILES_LIST="$(ls srv_*.log 2>/dev/null)"
for file in $FILES_LIST; do
    #something with $file

Bash regex matching not working

Tag : regex , By : 40a
Date : March 29 2020, 07:55 AM
help you fix your problem so I have this function , Don't use quotes ""
if [[ "$output" =~ ^CMD\[.*?\]$ ]]; then

Regex matching end of a line $ not working in Bash Script

Tag : regex , By : Gerhard Miller
Date : March 29 2020, 07:55 AM
This might help you I'm trying to do a simple regex statement in a bash script that will match and substitute the end of a word. Below is what I'm trying to do. , The regex's there are a little different. Try:
.         The pattern is expanded to produce a pattern just as in pathname
          expansion.   Parameter is expanded and the longest match of pat-
          tern against its value is replaced  with  string.   If  Ipattern
          begins  with /, all matches of pattern are replaced with string.
          Normally only the first match is replaced.   If  pattern  begins
          with  #, it must match at the beginning of the expanded value of
          parameter.  If pattern begins with %, it must match at  the  end
          of  the expanded value of parameter.  If string is null, matches
          of pattern are deleted and the / following pattern may be  omit-
          ted.   If  parameter  is  @  or *, the substitution operation is
          applied to each positional parameter in turn, and the  expansion
          is  the  resultant list.  If parameter is an array variable sub-
          scripted with @ or *, the substitution operation is  applied  to
          each  member  of  the  array  in  turn, and the expansion is the
          resultant list.

Bash regex script not matching

Tag : bash , By : user177910
Date : March 29 2020, 07:55 AM
This might help you I made this batch script that is parsing a file and displaying my values if found : , Bash does not support \d, \s.
[STEP 100] $ echo $BASH_VERSION
[STEP 101] $ d4='[[:digit:]]{4}'
[STEP 102] $ d2='[[:digit:]]{2}'
[STEP 103] $ d3='[[:digit:]]{3}'
[STEP 104] $ ds='[[:digit:]]+'
[STEP 105] $ re="^($d4-$d2-$d2 $d2:$d2:$d2,$d3) .*:($ds)\$"
[STEP 106] $ str='2017-03-24 07:51:43,368 my log id :469565'
[STEP 107] $ [[ $str =~ $re ]]
[STEP 108] $ echo $?
[STEP 109] $ echo ${BASH_REMATCH[1]}
2017-03-24 07:51:43,368
[STEP 110] $ echo ${BASH_REMATCH[2]}
[STEP 111] $
Related Posts Related QUESTIONS :
  • How do I use a variable in Perl regex/replace?
  • Remove special characters and add a semi colon in a word - Tableau
  • Howto check if the first 4 characters of first name and first 4 characters of last name appear in the username
  • Qt: Regex max. 9 digits (Int and Float)
  • RegEx for ignoring certain words
  • Remove lines with more than x digits
  • How to capture everything until another capture group
  • How to find double letters and replace them with triple letters?
  • A regular expression for matching a group followed by a specific character
  • How to replace a whitespace between a group of numbers with a dot or a comma?
  • Regex to encode an URL with special characters
  • regex pattern not fit well for code like assignment
  • Regex remove first section and optional last section
  • Regex for patterns like [ABC], ABC and ABCxx where xx is a number
  • RegEx for identifying alphanumeric patterns with special chars and boundaries
  • Is sed auto in-place substitution?
  • Preventing a regex from matching by using a negative look behind
  • Regex to extract name from a string
  • Why is 1100 matched by /(0*1(00)*10*)*/?
  • Need regex pattern for input text box allowing numbers between 0 to 100 and up to 2 decimals eg., 0.22 to 100.00
  • Regular expression cannot match "</p>" correctly
  • Using htaccess, how do you re-write for parameters over 8 characters or more only?
  • RegEx for extracting part of HTML elements
  • Extract a specific term 'hardrock'
  • How to replace some patterns with whitespace in perl?
  • RegEx for extracting a value from URLs
  • Regex match between parenthesis stopping at first space within parenthesis
  • Why does Scala regexp work differently in pattern matching
  • Parse default Salt highstate output
  • How to match a 10-char string ending with 2 Digits?
  • RegEx for substituting only to the left of LaTeX comments
  • RegEx for removing lines that have the same id in Notepad++
  • Change formatting of inline comments from // to /* */
  • Parsing multiline quoted strings in a large file
  • RegEx capturing group in Elixir
  • RegEx for identifying a date followed by a special pattern
  • RegEx for transforming the next text using PhpStorm's search and replace dialog
  • RegEx for matching everything except a text between two words
  • How to use grep to match a string containing [], the characters in [] are composed of uppercase and lowercase letters an
  • RegEx for matching numbers from 0.00 to 50.00
  • Perl search and replace: replacing end of line replaces beginning to line too
  • XSD Pattern Restriction - Alternation with forward slash
  • Is there a way to replace the first '/' from a string conditionally?
  • split the string with pattern python
  • RegEx: How can I match all characters until the next match?
  • AWK - add value based on regex
  • Extract a sub-string from a matched string
  • extract substring from string in perl
  • How do I capture the last two characters in this regex?
  • Replacing all characters in a regular expression match with another character?
  • Regex - Ignore lines with matching text
  • extjs input text maskRe
  • regex question: independent position of words
  • Regex to match words and those with an apostrophe
  • How do I use a regular expression to match any string, but at least 3 characters?
  • How do I remove duplicate characters and keep the unique one only in Perl?
  • How can I extract a substring from a string using regular expressions?
  • Using regexp to search for the string matching multiple words arranged in random
  • How can I print lines that match a pattern in Perl?
  • What is the regex patten for this?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com