{"id":587,"date":"2014-03-27T07:04:25","date_gmt":"2014-03-27T14:04:25","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=587"},"modified":"2014-03-27T07:06:30","modified_gmt":"2014-03-27T14:06:30","slug":"howto-grab-additional-lines-when-grep-is-ancient","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/howto-grab-additional-lines-when-grep-is-ancient\/","title":{"rendered":"Howto grab additional lines when grep is ancient"},"content":{"rendered":"

In modern grep utilities can use -A (after) and -B (before) to return additional lines from your search. Solaris 11 still does not have a grep that can do this. Several options exist but this is one that worked for me.<\/p>\n

Example output without grep. I wanted Vendor and one extra line after for Size.<\/p>\n

\r\n# iostat -E\r\n[...]\r\nssd24     Soft Errors: 0 Hard Errors: 0 Transport Errors: 0\r\nVendor: 3PARdata Product: VV               Revision: 3123 Serial No: 1203842\r\nSize: 268.44GB <268435456000 bytes>\r\nMedia Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0\r\nIllegal Request: 0 Predictive Failure Analysis: 0\r\nssd25     Soft Errors: 0 Hard Errors: 0 Transport Errors: 0\r\nVendor: 3PARdata Product: VV               Revision: 3123 Serial No: 1203842\r\nSize: 273.80GB <273804165120 bytes>\r\nMedia Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0\r\n[..]\r\n<\/pre>\n

One possible way with awk. \"ssd\" was my start and \"2\" was my number of lines after.<\/p>\n

\r\n# iostat -E | awk '\/'"ssd"'\/{l=1;count=NR;next} l>0 && NR-count < '"2"+1' {print}'\r\nVendor: 3PARdata Product: VV Revision: 3123 Serial No: .....\r\nSize: 268.44GB\r\nVendor: 3PARdata Product: VV Revision: 3123 Serial No: .....\r\nSize: 273.80GB\r\nVendor: 3PARdata Product: VV Revision: 3123 Serial No: .....\r\nSize: 536.87GB\r\nVendor: SUN Product: ZFS Storage 7330 Revision: 1.0 Serial No:\r\nSize: 37.58GB\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

In modern grep utilities can use -A (after) and -B (before) to return additional lines from your search. Solaris 11<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-587","post","type-post","status-publish","format-standard","hentry","category-solaris"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=587"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/587\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}