Greens8301
asked on
In UNIX grep a phrase and adjacent lines
I like to cat the file and grep a phrase and necxt 3 lines
EX
<>
SELECT t1.commerce_item_id,t1.typ e,t3.ship_ date
FROM dcspp_item t1
LEFT OUTER JOIN usps_label_items t3 ON t3.commerce_item_id=t1.com merce_item
WHERE t2.order_id=t1.order_ref
AND ((t1.type = ?)
AND ((t2.profile_id = ?)
AND ((t2.state = ?)
OR (t2.state = ?)
OR (t2.state = ?)
OR (t2.state = ?)
OR (t2.state = ?))
AND (t3.ship_date >= ?)
AND (t3.ship_date <= ?)))
ORDER BY t3.ship_date ASC
-- Parameters --
p[1] = {pd: type} 4003 (java.lang.Integer)
p[2] = {pd: profileId} 1320006 (java.lang.String)
p[3] = {pd: state} SUBMITTED (java.lang.String)
p[4] = {pd: state} PROCESSING (java.lang.String)
p[5] = {pd: state} PENDING_MERCHANT_ACTION (java.lang.String)
p[6] = {pd: state} PENDING_CUSTOMER_ACTION (java.lang.String)
p[7] = {pd: state} NO_PENDING_ACTION (java.lang.String)
p[8] = {pd: shipDate} 2010-11-09 (java.sql.Date)
p[9] = {pd: shipDate} 2010-11-14 (java.sql.Date)
<>
When I grep SELECT, for above lines of code I like to see only 3 lines
SELECT t1.commerce_item_id,t1.typ e,t3.ship_ date
FROM dcspp_item t1
LEFT OUTER JOIN usps_label_items t3 ON t3.commerce_item_id=t1.com merce_item
There are several SELECT ( 300) in the 5000 lines of file,
I like to grep each SELECT and next 2 lines
Is this possible to do
If so, I'll appreciate, if any one can help
Thanks
EX
<>
SELECT t1.commerce_item_id,t1.typ
FROM dcspp_item t1
LEFT OUTER JOIN usps_label_items t3 ON t3.commerce_item_id=t1.com
WHERE t2.order_id=t1.order_ref
AND ((t1.type = ?)
AND ((t2.profile_id = ?)
AND ((t2.state = ?)
OR (t2.state = ?)
OR (t2.state = ?)
OR (t2.state = ?)
OR (t2.state = ?))
AND (t3.ship_date >= ?)
AND (t3.ship_date <= ?)))
ORDER BY t3.ship_date ASC
-- Parameters --
p[1] = {pd: type} 4003 (java.lang.Integer)
p[2] = {pd: profileId} 1320006 (java.lang.String)
p[3] = {pd: state} SUBMITTED (java.lang.String)
p[4] = {pd: state} PROCESSING (java.lang.String)
p[5] = {pd: state} PENDING_MERCHANT_ACTION (java.lang.String)
p[6] = {pd: state} PENDING_CUSTOMER_ACTION (java.lang.String)
p[7] = {pd: state} NO_PENDING_ACTION (java.lang.String)
p[8] = {pd: shipDate} 2010-11-09 (java.sql.Date)
p[9] = {pd: shipDate} 2010-11-14 (java.sql.Date)
<>
When I grep SELECT, for above lines of code I like to see only 3 lines
SELECT t1.commerce_item_id,t1.typ
FROM dcspp_item t1
LEFT OUTER JOIN usps_label_items t3 ON t3.commerce_item_id=t1.com
There are several SELECT ( 300) in the 5000 lines of file,
I like to grep each SELECT and next 2 lines
Is this possible to do
If so, I'll appreciate, if any one can help
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER