LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 12-20-2006, 08:14 PM   #1
vikram_cvk
Member
 
Registered: Jan 2004
Location: Hyderabad , India
Distribution: RHL 9
Posts: 42

Rep: Reputation: 15
GREP - reg exp to find words ending with .V and .TO


Hello Experts,

Im trying to extract the words ending with .V or .TO from the following list

AVWI.OB
AVX
AVX-P.V
AVXT.OB
AVY
AVZ
AVZ.TO
AW
AWB.V
AWBC
AWC
AWF
AWG
AWX.V
AXA

Im new to grep/regexp, Im breaking my head trying to figure out wot would be the righ grep command for that ...

I tried the following options , but im not able to construct the correct regular expression

$ grep -o '[ A-Z][a-z].V' StockList30.txt
$ grep -o '[ A-Z][a-z].TO' StockList30.txt

Plz help me out in constructing the right grep command to retrieve words ending with .V and .TO.


Thx in advance.

Regards
Swiftguy
 
Old 12-20-2006, 08:26 PM   #2
kbrede
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Rep: Reputation: 0
egrep -e '\.TO|\.V' test.txt
works for me.
 
Old 12-20-2006, 09:37 PM   #3
vikram_cvk
Member
 
Registered: Jan 2004
Location: Hyderabad , India
Distribution: RHL 9
Posts: 42

Original Poster
Rep: Reputation: 15
GREP - reg exp to find words ending with .V and .TO

Hello kbrede,

Thx for providing the solution, im trying to extract the words ending with .V or .TO from a html file, How can i avoid the complete line and only the search strings to be displayed(cleaning the html code) ?

Following is the result when i tried your solution on a html file,




$egrep -e '\.TO|\.V' StockList30.html (enter) ..sample output is..



<td><font color="Black"><a href="http://charts.tradingchief.com/DBDemos/CustomChart.aspx?Symbol=AVV.V">Chart</a></font></td><td><font color="Black">AVV.V</font></td><td><font color="Black">AVANTEC TECHNOLOGIES INC. (Tier</font></td><td><font color="Black">2006-12-19</font></td><td><font color="Black">0.05</font></td><td><font color="Black">0.05</font></td><td><font color="Black">0.05</font></td><td><font color="Black">0.05</font></td><td><font color="Black">0.05</font></td><td><font color="Black">14000.00</font></td><td><font color="Red">-9.09 %</font></td><td><font color="Black">CDNX</font></td>


<td><font color="Black"><a href="http://charts.tradingchief.com/DBDemos/CustomChart.aspx?Symbol=AVZ.TO">Chart</a></font></td><td><font color="Black">AVZ.TO</font></td><td><font color="Black">AMVESCAP Inc</font></td><td><font color="Black">2006-12-20</font></td><td><font color="Black">13.00</font></td><td><font color="Black">12.99</font></td><td><font color="Black">12.99</font></td><td><font color="Black">12.85</font></td><td><font color="Black">12.90</font></td><td><font color="Black">24078.00</font></td><td><font color="Red">-0.77 %</font></td><td><font color="Black">Toronto</font></td>


I want only the words in bold i.e AVZ.TO and AVV.V to be displayed.

Plz help me out

Thanking you,

Regards
 
Old 12-20-2006, 09:55 PM   #4
zetabill
Member
 
Registered: Oct 2005
Location: Rhode Island, USA
Distribution: Slackware, Xubuntu
Posts: 348

Rep: Reputation: 30
Code:
grep -o '[A-Z]*\.V\|[A-Z]*\.TO' StockList30.html
Is this a homework question?

Last edited by zetabill; 12-20-2006 at 10:00 PM.
 
Old 12-22-2006, 10:22 AM   #5
vikram_cvk
Member
 
Registered: Jan 2004
Location: Hyderabad , India
Distribution: RHL 9
Posts: 42

Original Poster
Rep: Reputation: 15
Hi,

This is no homework job! im new to grep and i need a quick solution to extract data for a small task on hand.

Thx for the solution,

Last edited by vikram_cvk; 12-22-2006 at 10:32 AM.
 
Old 12-22-2006, 01:47 PM   #6
zetabill
Member
 
Registered: Oct 2005
Location: Rhode Island, USA
Distribution: Slackware, Xubuntu
Posts: 348

Rep: Reputation: 30
Okay... It just sounded a lot like a homework question I once had in my bash class some moons ago. I'm glad that it worked for you though. That's why we're here.

For future reference:
Code:
grep -o 'regular expression' StockList30.html
will find in the html file only the part of the line that matches the regular expression. Since you were trying to find something that isn't part of another word or phrase (I.E. it's wrapped in tags or whitespaces) this works just fine... but I think you got that already.
Code:
[A-Z]*\.V
This will look for zero or more capital letters followed by a ".V". The backslash is to escape the period because it is a special character and escaping it tells grep that you're looking for a period and not any single character.
Code:
\|
Think of this as a separator... an OR if you will. It needs to be escaped as well.
Code:
[A-Z]*\.TO
Same as before but with the TO extension.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
python reg exp help Bopi Programming 1 12-03-2006 02:29 AM
Problem with reg exp script abefroman Programming 2 12-19-2005 03:53 PM
Perl Reg Exp Question amytys Programming 1 12-09-2005 12:53 PM
prob with reg exp rajatgarg Programming 3 05-28-2004 09:21 AM
Reg Exp ugenn Programming 4 09-19-2002 12:01 PM


All times are GMT -5. The time now is 10:59 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