LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-26-2012, 03:35 AM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431
Blog Entries: 31

Rep: Reputation: 3
escaping single quote with regex


Hi, I am having trouble trying to get my intended results from this code:
Code:
torrentlink=($(sed -rn "/target=/s/.*href=\"([^\"]+)\".*>.*\.${vars[1]}\.torrent.*/\1/p" "$html"))
torrentlink=($(sed -rn "/target=/s/.*href=\"([^\"]+)\".*>.*\.${vars[1]}\.torrent.*/\1/p" "$html"))
I believe I am not correct in trying to escape the single quote, but there is an array defined term in the variable, so this makes the coding even more difficult.
Another question that I have is whether the . for file extension needed backslash to escape, because they seem to be working fine with or without backslashes.
THanks,
Ted
 
Old 06-26-2012, 04:17 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
I haven't looked at the sed command (others here can do that better than I) but, assuming this is in a bash script,
Code:
torrentlink=($(sed <whatever>))
will not assign anything to variable torrentlink, it will simply (try to) run the output of the sed command in a subshell, writing the output to stdout which is probably the terminal.

Assuming you want the output of the sed command in variable torrentlink:
Code:
torrentlink=$(sed <whatever>)
What is the output of the sed command alone? For debugging:
Code:
sed <whatever>
torrentlink=$(sed <whatever>)
 
1 members found this post helpful.
Old 06-26-2012, 11:23 PM   #3
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431

Original Poster
Blog Entries: 31

Rep: Reputation: 3
Thanks, I solved by using both double and single quotes:
Code:
torrentlink=($(sed -rn '/target=/s/.*href="([^"]+)".*>.*\.'"${vars[1]}"'\.torrent.*/\1/p' "$html"))
This seem to work perfectly without errors, the point of adding double quotes for ${var[1]} in cases of space or tab characters in the variable.
Thanks,
Ted
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote akudewan Linux - Newbie 5 07-28-2014 12:16 PM
[SOLVED] How to pass a single quote inside of a single quote... trist007 Linux - Newbie 2 02-09-2011 07:07 PM
[SOLVED] escaping a single quote from a bash script atbrew Programming 8 07-21-2010 09:21 AM
[SOLVED] How to escape single quote btacuso Linux - Newbie 3 03-11-2010 10:58 AM
xargs: unmatched single quote fillatre Linux - Software 2 06-05-2004 10:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration