aradhak
aradhak

Reputation: 836

Shell Scripting - URL manipulation

I need to manipulate a URL from the values from a file. This is what I could do

var=$(grep -A2 -i "some_text" /path/to/file | grep -v "some_text" | cut -d'"' -f 4-5 | cut -d'"' -f 1 | tr -d '\n')

This will give output : /text/to/be/appended/to/domain

Now, I need to append the domain name to var value.

So I did,

var1="http://mydomain"

and then

echo ${var1}${var}

So I expect

http://mydomain/text/to/be/appended/to/domain

to be the output. But am getting just /text/to/be/appended/to/domain.

I guessed it'd be due to the / as the first char, but if i use cut to remove the first /, am getting value of var1 as output.

Where did I go wrong?

Update (not sure if this would help even a bit, still) :

If I do echo ${var}${var1}, am getting /text/to/be/appended/to/domainhttp://mydomain

Sample entry :

<tr><td><a id="value">some_text</a></td></tr>
<tr><td><a id="value" href="/text/to/be/appended/to/domain">2013</a></td></tr>

Upvotes: 1

Views: 290

Answers (1)

Paul Sweatte
Paul Sweatte

Reputation: 24617

this line ending (^M) points that at some point the file was edited(created) in dos like environment. Use "dos2unix yourfile" to fix the problem. BOTH your script and the sample entries.

Upvotes: 2

Related Questions