Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-22-2017   -   Original Discussion by gvkumar25
gvkumar25's Unix or Linux Image
gvkumar25 gvkumar25 is offline
Registered User
 
Join Date: Jul 2014
Last Activity: 10 June 2017, 4:12 AM EDT
Posts: 43
Thanks: 13
Thanked 0 Times in 0 Posts
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

Sponsored Links
    #2  
Old Unix and Linux 03-22-2017   -   Original Discussion by gvkumar25
rovf's Unix or Linux Image
rovf rovf is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 15 January 2018, 2:25 AM EST
Posts: 196
Thanks: 29
Thanked 43 Times in 37 Posts
  1. How are you reading the file? Show the code.
  2. What shell are you using?
Sponsored Links
    #3  
Old Unix and Linux 03-22-2017   -   Original Discussion by gvkumar25
gvkumar25's Unix or Linux Image
gvkumar25 gvkumar25 is offline
Registered User
 
Join Date: Jul 2014
Last Activity: 10 June 2017, 4:12 AM EDT
Posts: 43
Thanks: 13
Thanked 0 Times in 0 Posts
I am using a k shell.


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

    #4  
Old Unix and Linux 03-22-2017   -   Original Discussion by gvkumar25
rovf's Unix or Linux Image
rovf rovf is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 15 January 2018, 2:25 AM EST
Posts: 196
Thanks: 29
Thanked 43 Times in 37 Posts
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?
Sponsored Links
    #5  
Old Unix and Linux 03-22-2017   -   Original Discussion by gvkumar25
durden_tyler's Unix or Linux Image
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
 
Join Date: Apr 2009
Last Activity: 9 September 2017, 1:30 PM EDT
Posts: 2,083
Thanks: 21
Thanked 383 Times in 346 Posts
Quote:
Originally Posted by gvkumar25 View Post
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)
Sponsored Links
    #6  
Old Unix and Linux 03-23-2017   -   Original Discussion by gvkumar25
gvkumar25's Unix or Linux Image
gvkumar25 gvkumar25 is offline
Registered User
 
Join Date: Jul 2014
Last Activity: 10 June 2017, 4:12 AM EDT
Posts: 43
Thanks: 13
Thanked 0 Times in 0 Posts
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,\}

Sponsored Links
    #7  
Old Unix and Linux 03-23-2017   -   Original Discussion by gvkumar25
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 21 January 2018, 3:51 PM EST
Location: Amsterdam
Posts: 11,712
Thanks: 532
Thanked 3,400 Times in 2,996 Posts
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)
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Please delete my post which was posted wrongly bhas85 Post Here to Contact Site Administrators and Moderators 1 09-04-2015 03:23 PM
awk seems to be wrongly placed? emily Shell Programming and Scripting 0 03-10-2015 10:24 AM
Putty recognise keystroke wrongly! linwufei125 Red Hat 4 06-27-2012 12:51 AM
wrongly linked my new file .. siddaonline UNIX for Dummies Questions & Answers 4 06-02-2008 06:27 AM
wrongly encapsulated appdg instead of rootdg ishila Solaris 5 10-27-2005 03:28 PM



All times are GMT -4. The time now is 08:43 PM.