Delete lines before a match

  • Follow


How can I delete all the lines before a match using only awk?
Thank you
0
Reply mazacar (1) 3/31/2005 12:36:48 AM

On Thu, 31 Mar 2005 at 00:36 GMT, Itaca wrote:
> How can I delete all the lines before a match using only awk?

awk '/pattern/ { ++ok } ok'

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2005, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
0
Reply Chris 3/31/2005 12:51:29 AM


"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote in message news:<h5urh2-k9g.ln1@xword.rogers.com>...
> On Thu, 31 Mar 2005 at 00:36 GMT, Itaca wrote:
> > How can I delete all the lines before a match using only awk?
> 
> awk '/pattern/ { ++ok } ok'

It works! Thank you !
Another related question. How can I delete all the lines AFTER the match?
Thank you
0
Reply mazacar 3/31/2005 10:05:06 AM

Itaca wrote:
> "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote in message news:<h5urh2-k9g.ln1@xword.rogers.com>...
> 
>>On Thu, 31 Mar 2005 at 00:36 GMT, Itaca wrote:
>>
>>>How can I delete all the lines before a match using only awk?
>>
>>awk '/pattern/ { ++ok } ok'
> 
> 
> It works! Thank you !
> Another related question. How can I delete all the lines AFTER the match?
> Thank you

/pattern/ { exit } 1


Janis
0
Reply Janis 3/31/2005 11:45:09 AM

Janis Papanagnou wrote:
> Itaca wrote:
> 
>> "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote in message 
>> news:<h5urh2-k9g.ln1@xword.rogers.com>...
>>
>>> On Thu, 31 Mar 2005 at 00:36 GMT, Itaca wrote:
>>>
>>>> How can I delete all the lines before a match using only awk?
>>>
>>>
>>> awk '/pattern/ { ++ok } ok'
>>
>> It works! Thank you !
>> Another related question. How can I delete all the lines AFTER the match?
>> Thank you
> 
> /pattern/ { exit } 1

Above includes deleting the pattern line. If you don't want the pattern
line to be deleted you may write write:

{ print } /pattern/ { exit }


Janis
0
Reply Janis 3/31/2005 11:51:43 AM

4 Replies
454 Views

(page loaded in 0.109 seconds)

Similiar Articles:













7/23/2012 7:24:15 PM


Reply: