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

  • Home
  • SEARCH
  • 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 9015557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:46:40+00:00 2026-06-16T03:46:40+00:00

I want to remove 1st character on file when grep some string. But need

  • 0

I want to remove 1st character on file when grep some string. But need that changed row to be on the same position before the edit.

Example file:

#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
auth            include         system-auth
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet

Expected View after the edit:

#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
auth           sufficient      pam_wheel.so trust use_uid
auth            include         system-auth
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet

In that case on 4th row need just to remove “#”, but I want to do that when search the string “sufficient pam_wheel.so trust use_uid” not when point the exact row that I want to edit.

  • 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-16T03:46:41+00:00Added an answer on June 16, 2026 at 3:46 am

    This is a job for sed:

    $ sed -r 's/^#(.*sufficient\s+pam_wheel\.so trust use_uid.*)/\1/' file
    #%PAM-1.0
    auth            sufficient      pam_rootok.so
    # Uncomment the following line to implicitly trust users in the "wheel" group.
    auth           sufficient      pam_wheel.so trust use_uid
    auth            include         system-auth
    account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
    

    Regexplanation:

    s/                            # Substitute  
    ^#                            # A line starting with a #
    (                             # Start capture group
    .*                            # Followed by anything
    sufficient                    # Followed by the word sufficient
    \s+                           # Followed by whitespace
    pam_wheel\.so trust use_uid   # Followed by the literal string (escaped .)
    .*                            # Followed by anything
    )                             # Stop capture group
    /                             # Replace with 
    \1                            # The first capture group 
    

    So effectively we are matching lines starting with # containing the string sufficient\s+pam_wheel.so trust use_uid and removing the #

    Notes: the -r flag is for extended regexp, it might be -E for your version of sed so check the man.

    If you want to store the changes back to the file use the -i option:

    $ sed -ri 's/^#(.*sufficient\s+pam_wheel\.so trust use_uid.*)/\1/' file
    

    If the column aligment is important then capture up to sufficient and after it so you get 2 capture groups and replace with \1 \2.

    $ sed -r 's/^#(.*)(sufficient\s+pam_wheel\.so trust use_uid.*)/\1 \2/' file
    #%PAM-1.0
    auth            sufficient      pam_rootok.so
    # Uncomment the following line to implicitly trust users in the "wheel" group.
    auth            sufficient      pam_wheel.so trust use_uid
    auth            include         system-auth
    account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
    

    Edit:

    Replace the string AllowUsers support admin with #AllowUsers support admin:

    $ sed -r 's/^(AllowUsers support admin.*)/#\1/' file
    #AllowUsers support admin
    
    $ sed -r 's/^(DeniedUsers root.*)/#\1/' file
    #DeniedUsers root
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to remove the string code=hads1328fas& on my URL, so that BEFORE http://example.com/main/index.php?code=hads1328fas&store=food#home
I want to remove the decimal part of a number in a cell but
i want to remove the link from my header using CSS so that only
I want to remove the last right border in a row of links? #mainMenu
I want to remove duplicate lines from a file, without sorting the file. Example
I want to remove the whitespace between the arrays, but I've used different codes
I want to remove an item from ListView , but I don't know how
How remove block in dxf file format? I want to do this to change
I have some duplicate code like below, I want remove the duplicate code, to
I want remove an xml node from an xml document, but I don't know

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.