0

I'm using this code to get all titles from urls with http://something.txt:

#!/usr/bin/perl -w
$output = `cat source.html | grep -o '<a .*href=.*>' | grep -E 'txt' | sed -e 's/<a /\n<a /g' | sed -e 's/<a .*title="//' | cut -f1 -d '"'`;

print("$output");

When i run this on perl i get the error:

sed: -e expression #1, char 6: unterminated `s' command

The error is related with this portion of code:

sed -e 's/<a /\n<a /g'
4
  • 1
    where you actually mentioned the file name? Commented Apr 6, 2015 at 16:45
  • @AvinashRaj that's not the problem... Commented Apr 6, 2015 at 16:48
  • I don't see any perl in your code. What are you really trying to do? Commented Apr 6, 2015 at 16:53
  • @ghoti i've just added all the code. Commented Apr 6, 2015 at 16:55

1 Answer 1

2

In backquotes, Perl uses the same rules as in double quotes. Therefore, \n corresponds to a newline; you have to backslash the backslash to pass literal \ to the shell:

`sed -e 's/<a /\\n<a /g'`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.