Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6080033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:00:57+00:00 2026-05-23T11:00:57+00:00

I have a large logfile and I want to extract (write to a new

  • 0

I have a large logfile and I want to extract (write to a new file) certain rows. The problem is I need a certain row and the row before. So the regex should be applied on more than one row. Notepad++ is not able to do that and I don’t want to write a script for that.

I assume I can do that with Powershell and a one-liner, but I don’t know where to start …

The regular expression is not the problem, will be something like that ^#\d+.*?\n.*?Failed.*?$

So, how can I open a file using the Powershell, passing the regex and get the rows back that fits my expression?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:00:58+00:00Added an answer on May 23, 2026 at 11:00 am

    Look at Select-String and -context parameter:

    If you only need to display the matching line and the line before, use
    (for a test I use my log file and my regex – the date there)

    Get-Content c:\Windows\System32\LogFiles\HTTPERR\httperr2.log  |
        Select-String '2011-05-13 06:16:10' -context 1,0
    

    If you need to manipulate it further, store the result in a variable and use the properties:

    $line = Get-Content c:\Windows\System32\LogFiles\HTTPERR\httperr2.log  |
            Select-String '2011-05-13 06:16:10' -context 1
    
    # for all the members try this:
    $line | Get-Member
    
    #line that matches the regex:
    $line.Line
    $line.Context.PreContext
    

    If there are more lines that match the regex, access them with brackets:

    $line = Get-Content c:\Windows\System32\LogFiles\HTTPERR\httperr2.log  |
            Select-String '2011-05-13 06:16:10' -context 1
    $line[0] # first match
    $line[1] # second match
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On a Linux system, I have a very large text file and I need
i have large numbers of text files and i am in problem that i
I have large set of flow charts and workflow diagrams. I want to draw
I have the need to stream a log file that is located on FTP,
We have large (2M+ row) product data tables with 50+ data fields and multiple
I have large text containers and i want to compare and highlight them using
I have large text. I need to find an URL and replace the found
I have a very large error log file( around 200 MB),in a remote server
I have a large set of log files that I want to characterize or
I have an existing .net service, and I want to configure it to write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.