Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  11] [ 0]  / answers: 1 / hits: 22430  / 1 Year ago, sat, may 27, 2023, 2:33:55

I have a file which consists of a URL. I'm trying to get the URL from that file using a shell script.



In the file, the URL is like this:



('URL', 'http://url.com');


I tried to use the following:



cat file.php | grep 'URL' | awk '{ print $2 }'


It gives the output as:



'http://url.com');


But I need to get only url.com in a variable inside the shell script. How can I accomplish this?


More From » bash

 Answers
4

Something like this?



grep 'URL' file.php | rev | cut -d "'" -f 2 | rev


or



grep 'URL' file.php | cut -d "'" -f 4 | sed s/'http://'/''/g


To strip out http://.


[#26955] Sunday, May 28, 2023, 12 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ingsta

Total Points: 391
Total Questions: 103
Total Answers: 124

Location: Bonaire
Member since Wed, Mar 29, 2023
1 Year ago
ingsta questions
Sun, Oct 23, 22, 01:42, 2 Years ago
Sat, Oct 30, 21, 11:27, 3 Years ago
Sun, Nov 28, 21, 12:49, 2 Years ago
;