REGEXPRESSION Getting wrongly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting REGEXPRESSION Getting wrongly
# 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,\}|
$ 
$

This User Gave Thanks to durden_tyler For This Post:
# 6  
Old 03-23-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"

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command within script wrongly deleting the last line

Hi, I have a shell script which has a for loop that scans list of files and do find and replace few variables using sed command. While doing this, it deletes the last line of all input file which is something wrong. how to fix this. please suggest. When i add an empty line in all my input file,... (5 Replies)
Discussion started by: rbalaj16
5 Replies

2. Solaris

How to recover wrongly deleted volume in VxVM?

Hi On solaris 10 system my one veritas volume got accidently deleted. Now could any one tell me how to recover it. If I am taking regular backup of disk group of that volume through vxconfigbackup as I want to recover only particular volume only. (1 Reply)
Discussion started by: amity
1 Replies

3. Post Here to Contact Site Administrators and Moderators

Please delete my post which was posted wrongly

Hi Moderator, Please delete the below post which i posted by mistake.Thanks in advance. https://www.unix.com/shell-programming-and-scripting/260605-closed-script-not-working-new-post.html Kindly help me on this. Thanks, vijay (1 Reply)
Discussion started by: bhas85
1 Replies

4. Shell Programming and Scripting

awk seems to be wrongly placed?

Dear all, I have small script ( which after introducing few changes) is not working as desired way . The content of the output file from this script is following ----------- 1492033600... (0 Replies)
Discussion started by: emily
0 Replies

5. Red Hat

Putty recognise keystroke wrongly!

Putty: release 0.58 Operating system: Linux, release 2.6.36-rc7 Problem: I use Putty to connet to server, initially everthing looks fine but after I browse some files, my keyboard acts funny, like if I keyin "cd", I got "je" on the screen. :wall: This only happens on some existing files but... (4 Replies)
Discussion started by: linwufei125
4 Replies

6. UNIX for Dummies Questions & Answers

wrongly linked my new file ..

Hi All, I was trying to point /unix-> new unix kernel ( unix_64_A ).. but instead by mistakenly i did the other way ..my new unix ( unix_64_A -> /unix ) ?? .. unfortunately i have only one copy of unix_64_A ..is there any way to solve this problem ..please help me asap . Thanks Vamshi. (4 Replies)
Discussion started by: siddaonline
4 Replies

7. Solaris

wrongly encapsulated appdg instead of rootdg

hi guys, i was doing a fresh installation of vxvm 4.0 on solaris 8 Sun enterprise 3500 and when i ran vxinstall command it gave me option of appdg and appdg02 to be encapsulated . I wanted to encapsulate rootdg. i wrongly encapsulated appdg. is there any work around for this ? your response... (5 Replies)
Discussion started by: ishila
5 Replies
Login or Register to Ask a Question