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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:44:01+00:00 2026-05-12T07:44:01+00:00

How can you remove one line which contains the word SID in many files?

  • 0

How can you remove one line which contains the word SID in many files?

I wondering between sed and tr. However, neither of them seem to work for the purpose.
I also would like to have some flexibility because of the following reason.

The problem is actually slightly more challenging. I need to remove also one line after the match in some files, while one line before in the other files. The one line has the character & which determines whether to remove one line below or above or only the match.
It is likely that the easiest way is to make a list of different types of files and then remove the files in each list with different codes.

Examples of the data

Here &

    . "question_sent"
    . "&"                        // I do not want this line
    .  htmlspecialchars(SID)     // NOT wanted
    . "&"
    . "email="

No & here

    . "successful_registration&"
    . "SID="                    // Not wanted
    .  htmlspecialchars($SID)   // Not wanted
    . "&"                       // not wanted
    . "email="

The character & is now in HTML encoding that is &

  if(isset($_GET['ask_question'])) {
      echo  ("<li id='ask_question_active'><a href='?ask_question&amp;"
          .  htmlspecialchars(SID)   // not wanted
          . "&amp;"                 // not wanted
          . "email=
  • 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-12T07:44:02+00:00Added an answer on May 12, 2026 at 7:44 am

    I wouldn’t feel game to run a global search-and-replace when the code is so inconsistent. I would be using grep/vim to check each line, unless you seriously do have 10,000 changes to make. To use grep/vim, the steps would be something like this:

    1) Add the following to your .vimrc:

    " <f1> looks for SID in the current file
    map <f1> /\<SID\><CR>
    " <f2> goes to the next file
    map <f2> :next<CR><f1>
    
    " <f5> deletes only the current line, and goes to the next SID
    map <f5> dd
    " <f6> deletes the current line and the one above, and goes to the next SID
    map <f6> k2dd
    " <f7> deletes the current line and the one below, and goes to the next SID
    map <f7> 2dd
    " <f8> deletes the current line, and the one above AND the one below
    map <f8> k3dd
    

    2) This grep command will find all the files you need to change:

    grep -rl '\bSID\b' * > fix-these-files.txt
    

    You may need to tweak it slightly to make sure that it is finding all the files you need to change. Make sure it is correct before you go to the next step.

    3) Use vim to open all the files that need fixing, like this:

    vim '+set confirm' '+/\<SID\>' $(cat fix-these-files.txt)
    

    4) You should now have vim open, and looking at the first SID in the first file you need to change. Use the following steps to fix each occurrence of SID:

    • If you only need to delete the current line, press <F5>.
    • If you need to delete the line above at the same time, press <F6> instead of <F5>.
    • If you need to delete the line below at the same time, press <F7> instead of <F5>
    • If you need to delete the lines above and below at the same time, press <F8> instead of <F5>
    • Press <F1> to find an another occurrence of SID to fix.
    • When SID cannot be found in the current file any more, press <F2> to go to the next file.

    Exit vim when there are no more SIDs to be fixed.

    5) Check to make sure you got everything, by running the grep command from step (2) again. There should be no search matches.

    6) Delete the extra mappings you added to your .vimrc in step (1).

    Warning: I haven’t tested the steps above, if you use them, be careful that you only make exactly the changes you need!

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

Sidebar

Related Questions

How can one remove all text, but leave the structure intact? for example: <animals>
How can I remove those annoying Mac OS X .DS_Store files from a Git
Which features and services in Vista can you remove with nLite (or tool of
How can I remove duplicate values from an array in PHP?
How can I remove the very first 1 from any string if that string
How can I remove the black background color in the corners of the ellipse?
How can I remove the xmlns:... namespace information from each XML element in C#?
Is there any Visual Studio Add-In that can do the remove method refactoring? Suppose
How can I use jquery to remove a SPECIFIC div that has no children
How can I customise the Site Actions menu to remove or rename 'standard' menu

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.