LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep regex with wildcard (https://www.linuxquestions.org/questions/linux-newbie-8/grep-regex-with-wildcard-912582/)

yknot7 11-09-2011 12:03 AM

grep regex with wildcard
 
Hi -

I run a ls and from the output want to retain only part of the string using a wildcard

ls output
http://localhost/test.com/deploy
http://localhost/test1.com/deploy
http://localhost/test2.com/deploy

I am trying to use grep to output
test.com
test1.com
test2.com

Any help appreciated.

Thanks in advance

grail 11-09-2011 01:35 AM

ummm ... you have files called - http://localhost/test.com/deploy???

Are you retrieving test<blah> because you know the word is test or you need everything between certain slashes??
As you can see I could go on with questions but maybe you could think of adding some more information?

linuxwin2 11-09-2011 01:38 AM

Code:

$ls | grep test| cut -d "/" -f4

yknot7 11-09-2011 01:43 AM

It could be any word, test is just an example

http://localhost/test.com/deploy
http://localhost/myword.com/deploy
http://localhost/anything.com/deploy

Thanks

yknot7 11-09-2011 10:27 AM

[SOLVED] grep regex with wildcard
 
Quote:

Originally Posted by linuxwin2 (Post 4519501)
Code:

$ls | grep test| cut -d "/" -f4

This worked, thanks linuxwin2

Code:

grep -o "/\/.*/deploy"|cut -d "/" -f4

grail 11-10-2011 12:05 AM

So I'll bite .... How did that work? You do not seem to have anything for the grep to read from??

yknot7 11-10-2011 01:11 AM

Quote:

Originally Posted by grail (Post 4520294)
So I'll bite .... How did that work? You do not seem to have anything for the grep to read from??

Sorry I should have been more clear

here is the full command

Code:

ls s3://bucketname|grep -o "/\/.*/$UPGRADE"|cut -d "/" -f4
Thanks


All times are GMT -5. The time now is 05:52 PM.