#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    1
    Rep Power
    0

    Search a value in between two pattern/words from a file


    My file is like below,

    ------------------------------------------------
    Order=[<order id="EO427849240">
    1
    2
    3
    4
    5
    Order=[<order id="EO427849241">
    6
    7
    8
    9
    10
    Order=[<order id="EO427849242">
    11
    12
    13
    14
    15
    Order=[<order id="EO427849243">
    ------------------------------------------------
    Now i want the middle portion where i found EO427849242. I tried with sed but it does not give me the desired result.

    I used the command,
    sed -n '/Sandy Order/,/Sandy Order/p' Filename

    and it gives me the all the portion in the file from Start=Sandy Order and end=Sandy Order

    When I use the below command,
    sed -n '/Sandy Order/,/Sandy Order/p' Filename | grep EO427849242

    it only gave me the line
    Order=[<order id="EO427849242">

    But what i need is
    -----
    Order=[<order id="EO427849242">
    11
    12
    13
    14
    15
    -----

    Can anyone please help me on this. It will be really helpful.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,448
    Rep Power
    1751
    Apart from 'Sandy Order' not actually appearing in your example file ...

    Try:
    Code:
    sed -n '/Order=\[<order id="EO427849242">/,/Order/p' Filename | head -n-1
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo