👤
Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

REGEXPRESSION Getting wrongly

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 03-22-2017
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.


Code:
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.

Code:
echo $record 
Daily|xyz|abc_def_tem_[0-9]\\8

# 2  
Old 03-22-2017
  1. How are you reading the file? Show the code.
  2. What shell are you using?
# 3  
Old 03-22-2017
I am using a k shell.
Code:
while read -r record
do
echo $record
done <<< $(sed -n '4,$p' source_file)

# 4  
Old 03-22-2017
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?
# 5  
Old 03-22-2017
Quote:
Originally Posted by gvkumar25
I am using a k shell.
...
Assuming "a k shell" = "Korn shell"

Code:
$ 
$ 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,\}|
$ 
$

The Following User Says Thank You to durden_tyler For This Useful Post:
gvkumar25 (03-23-2017)
# 6  
Old 03-22-2017
My code is in the way you showed me but when I echo inside my for loop I am getting below o/p
Code:
Daily|xyz|abc_def_tem_[0-9]\\8

instead of
Code:
Daily|xyz|abc_def_tem_[0-9]\{8,\}

# 7  
Old 03-23-2017
Similar, but with one essential difference.

Note that durden_tyler used double quotes around the variable expansion:
Code:
echo "$record"

The Following User Says Thank You to Scrutinizer For This Useful Post:
gvkumar25 (03-23-2017)
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed command within script wrongly deleting the last line rbalaj16 Shell Programming and Scripting 5 03-16-2018 06:08 PM
How to recover wrongly deleted volume in VxVM? amity Solaris 1 09-07-2015 08:31 AM
Please delete my post which was posted wrongly bhas85 Post Here to Contact Site Administrators and Moderators 1 09-04-2015 02:23 PM
awk seems to be wrongly placed? emily Shell Programming and Scripting 0 03-10-2015 09:24 AM
Putty recognise keystroke wrongly! linwufei125 Red Hat 4 06-26-2012 11:51 PM
wrongly linked my new file .. siddaonline UNIX for Dummies Questions & Answers 4 06-02-2008 05:27 AM
wrongly encapsulated appdg instead of rootdg ishila Solaris 5 10-27-2005 02:28 PM


All times are GMT -4. The time now is 09:16 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?