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 8949175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:10:28+00:00 2026-06-15T13:10:28+00:00

What command must be used to grep items between 2 matching patterns from a

  • 0

What command must be used to grep items between 2 matching patterns from a file.
My file has lines like:

abc def ghi
abc bcd def (task Name: example)
##some other similar lines##

I need the data between Name: and ‘)’

I tried with the command

cat script.log | sed 's/Name:\(.*\)\)/\1/gp'

This command is not providing me with required result. Please guide me with this.

Also, is it possible to use $Name in place of “Name:” (using a variable that substitutes the original value)

  • 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-06-15T13:10:29+00:00Added an answer on June 15, 2026 at 1:10 pm

    Something like:

    cat script.log | sed -n '/Name:/s/^.*Name:\([^)]*\)).*$/\1/gp'
    

    should do the job.

    The biggest mistake that you had in your original expression is that you escaped the second parenthesis. When I run your snippet, I get an error:

    sed: 1: "s/Name:\(.*\)\)/\1/g": RE error: parentheses not balanced
    

    Even if you correct that, you will find that sed prints every line by default. Here is what the expression that I built up does.

    Sed expressions take the form of [address[,address]]function[arguments]. Your expression did not include either of the optional address elements. I included a single address (/Name:/) which matches any line that contains “Name:”. The function is the substitution function which requires two arguments – (1) a search pattern and (2) a replacement expression. The search pattern matches the entire line and extracts the segment of the line following “Name:” that contains zero or more characters until the first parenthesis. The “escaped” parentheses define the capture group and the unescaped one terminates the capture. The pattern includes the rest of the line (e.g., .*$). Since the entire line is matched, it will be replaced by the replacement expression which contains only the captured portion.

    Putting this all together, the simple sed statement matches any line containing “Name:” and replaces the entire line with the characters between Name: and the first left parenthesis ()). The -n flag and the addition of the p flag ensures that only the matched lines are printed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like a command-line (must be a command line!) read-eval-print-loop Scheme interpreter. But
in my project i used wpf + prism.Inside a view,i must invoke a command
What command line should I write to display the memory used by process as
The command line has eluded me for years. I started in 1999 so I
This command and output: % find . -name file.xml 2> /dev/null ./a/d/file.xml % So
MySqlCommand command = connection.CreateCommand(); command.CommandText = string.Format(SELECT * FROM characters WHERE account_id = '{0}',
I think that the format of this command changed since I've last used it,
I've used phonegap Build to create my .apk file and i'm trying to sign
This is my AbstractNHibernateDao, i'd like to use SaveOrUpdateCopy with Merge command, but when
Looking for a command line code formatter that can be used for bash code.

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.