LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   using grep (https://www.linuxquestions.org/questions/linux-general-1/using-grep-601272/)

dnoy 11-20-2007 08:51 PM

using grep
 
So i have a few question:

1. How do I grep between keywords? I want to grep a section between
keyword a and keyword b.

2. how do i extend some columns so they look better when using grep.

I am doing the following:

lynx http://money.cnn.com/data/ipo/upcoming/

and want this info:

Upcoming IPOs | Withdrawn IPOs
Company Shares Range Primary Underwriter Expected
SuccessFactors (SFSF) 0790000 8.00 - 10.00 Morgan Stanley
Iggys House (IGGY) 1400000 6.00 - 6.00 Northland Securities
CreditCards.com (CCRD) 10725000 13.00 - 15.00 Credit Suisse
...


when i use
w3m http://money.cnn.com/data/ipo/upcoming/ | grep -B1 -A40 "Upcoming IPOs"

i get:

SuccessFactors 8.00 Morgan Freddie, Fannie hunt
(SFSF) 10790000 - Stanley 11/20 Report for a few billion
10.00 Retire without
Iggys House 6.00 Northland pinching pennies
(IGGY) 1400000 - Securities 11/20 Report Oil makes fresh run
6.00 at $100, hits record
13.00 Credit high
CreditCards.com 10725000 - Suisse 11/20 Report
(CCRD) 15.00


so my first question is how do i use the keyword to search between Upcoming IPOs and more markets? My solution is to use -B and -A to accomplish this, but i know there is a better way.

the second question is how to i organize all the columns so they are like the first section? I want it to look nice so Fannie hunt (SFSF) is on the same line.


thank you

Tinkster 11-20-2007 09:32 PM

Hard to say since I can't see markets in your text. If they're on separate lines
awk's the tool for the job.
Code:

$ lynx --dump --width=132 http://money.cnn.com/data/ipo/upcoming/ |awk '/Upcoming IPOs/,/Markets/'
  Upcoming IPOs | [143]Withdrawn IPOs
                    Company                    Shares      Range    Primary Underwriter  Expected
    SuccessFactors (SFSF)                      10790000 8.00 - 10.00  Morgan Stanley      11/20    [144]Report
    Iggys House (IGGY)                        1400000  6.00 - 6.00  Northland Securities 11/20    [145]Report
    CreditCards.com (CCRD)                    10725000 13.00 - 15.00 Credit Suisse        11/20    [146]Report
    Ideation Acquisition Corp. (IDI.U)        10000000 8.00 - 8.00  Lazard              11/20    [147]Report
    Tremisis Energy Acquisition CORP II (TEAX) 9500000  8.00 - 8.00  Merrill Lynch        11/26    [148]Report
    Entropic Communications (ENTR)            10000000 9.00 - 11.00  Credit Suisse        12/6    [149]Report
    Triple-S Management (GTS)                  14000000 16.00 - 18.00 Credit Suisse        12/7    [150]Report
    CampusU (CMPS)                            3500000  5.50 - 6.50  Maxim Group LLC      12/10    [151]Report

  [152]More Markets



Cheers,
Tink

dnoy 11-20-2007 10:16 PM

thank you so much, this exactly what i needed!


All times are GMT -5. The time now is 12:41 AM.