REGEXPRESSION Getting wrongly

Hello Experts,

My requirement is to read a file which contains regular expression and use that expression in my find command.I will not use all the regular expression which is there inside the file, Based on certain condition I will use it for that day. I used below regular expression inside a file.

Daily|xyz|abc_def_tem_[0-9]\{8,\}|

I am reading each line using while loop. When I print the line which read it from file. I am getting below output.I am losing my curly braces and , in the output because of this my find command is giving error output.

echo $record 
Daily|xyz|abc_def_tem_[0-9]\\8
  1. How are you reading the file? Show the code.
  2. What shell are you using?

I am using a k shell.

while read -r record
do
echo $record
done <<< $(sed -n '4,$p' source_file)

Do you mean "Korn Shell" when you say "k shell"?

I'm not familiar with Korn Shell, but if <<< works there in a similar way as it does in bash, this would explain the effect you are experiencing. At least in bash, brace expansion is performed on the input word, which would explain why the braces disappear.

What exactly is the reason that you are using <<< here?

Assuming "a k shell" = "Korn shell"

$ 
$ cat source_file 
Daily|xyz|abc_def_tem_[0-9]\{8,\}|
$ 
$ cat process_file.sh 
#!/usr/bin/ksh
while read -r record
do
    echo "$record"
done <<< $(sed -n '1,$p' source_file)

$ 
$ ./process_file.sh 
Daily|xyz|abc_def_tem_[0-9]\{8,\}|
$ 
$ 
1 Like

My code is in the way you showed me but when I echo inside my for loop I am getting below o/p

Daily|xyz|abc_def_tem_[0-9]\\8

instead of

Daily|xyz|abc_def_tem_[0-9]\{8,\}

Similar, but with one essential difference.

Note that durden_tyler used double quotes around the variable expansion:

echo "$record"
1 Like