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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:21:10+00:00 2026-06-09T09:21:10+00:00

I need help with using sed to comment a matching lines and 4 lines

  • 0

I need help with using sed to comment a matching lines and 4 lines which follows it.
in a text file.

my text file is like this:

[myprocess-a]
property1=1
property2=2
property3=3
property4=4

[anotherprocess-b]
property1=gffgg
property3=gjdl
property2=red
property4=djfjf

[myprocess-b]
property1=1
property4=4
property2=2
property3=3

I want to prefix # to all the lines having text ‘[myprocess’ and 4 lines that follows it
expected output:

#[myprocess-a]
#property1=1
#property2=2
#property3=3
#property4=4

[anotherprocess-b]
property1=gffgg
property3=gjdl
property2=red
property4=djfjf

#[myprocess-b]
#property1=1
#property4=4
#property2=2
#property3=3

Greatly appreciate your help on this.

  • 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-09T09:21:11+00:00Added an answer on June 9, 2026 at 9:21 am

    You can do this by applying a regular expression to a set of lines:

    sed -e '/myprocess/,+4 s/^/#/' 
    

    This matches lines with ‘myprocess’ and the 4 lines after them. For those 4 lines it then inserts a ‘#’ at the beginning of the line.

    (I think this might be a GNU extension – it’s not in any of the “sed one liner” cheatsheets I know)

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

Sidebar

Related Questions

I'm quite new to SQLite databases and need help using an external text file
Need help writing a script downloads data from google insight using c# this is
i need help with this. I'am using JQuery's Dynamic Form plug-in, it duplicates my
I really need help this time - Joomla 2.5 and latest K2. I'm using
This is very specific. I need help with using a C# function in my
I need some help in using the NSURLCache to download a simple file. It
Can anyone help me to get substring using sed program? I have a file
I need help with regex. I'm using Dreamweaver to do so text editing. I
I need help with using VQmod, if anyone has any experience with, I'd appreciate
I need some help using regex in java. Im trying to achieve 2 different

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.