Find the answer to your Linux question:
Results 1 to 2 of 2
As this thread has been closed for some obscure reason, I'll just have to start a new one to post a slight improvement on using sed to print the last ...
  1. #1
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181

    Grep last pattern output

    As this thread has been closed for some obscure reason, I'll just have to start a new one to post a slight improvement on using sed to print the last occurrence of a pattern in a file:

    Code:
    sed -n '/pattern/x; ${x;p;}' file

  2. #2
    Just Joined!
    Join Date
    Jan 2009
    Location
    Halifax, NS
    Posts
    19
    If the OP from the previous thread was also wondering how to match the first pattern.

    You can do
    Code:
    grep 'pattern' file | head -1
    Could come in handy, it just did for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...