LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
 
LinkBack Search this Thread
Old 11-09-2011, 12:03 AM   #1
yknot7
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Rep: Reputation: Disabled
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
 
Old 11-09-2011, 01:35 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,192

Rep: Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784
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?
 
Old 11-09-2011, 01:38 AM   #3
linuxwin2
Member
 
Registered: Oct 2011
Posts: 44

Rep: Reputation: Disabled
Code:
$ls | grep test| cut -d "/" -f4
 
1 members found this post helpful.
Old 11-09-2011, 01:43 AM   #4
yknot7
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-09-2011, 10:27 AM   #5
yknot7
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
[SOLVED] grep regex with wildcard

Quote:
Originally Posted by linuxwin2 View Post
Code:
$ls | grep test| cut -d "/" -f4
This worked, thanks linuxwin2

Code:
grep -o "/\/.*/deploy"|cut -d "/" -f4
 
Old 11-10-2011, 12:05 AM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,192

Rep: Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784
So I'll bite .... How did that work? You do not seem to have anything for the grep to read from??
 
Old 11-10-2011, 01:11 AM   #7
yknot7
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
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
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wildcard/regex in bash command logicalfuzz Linux - General 2 10-27-2011 02:40 PM
[SOLVED] Combining regex in grep devUnix Linux - General 2 09-06-2011 11:11 AM
grep regex . matches new lines?! lambchops468 Linux - Newbie 3 03-24-2008 09:19 PM
regex in ls vs. grep jhwilliams Linux - Software 2 08-10-2007 10:14 PM
egrep/grep regex question buldir Programming 7 05-08-2006 07:17 PM


All times are GMT -5. The time now is 02:52 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration