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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:35:27+00:00 2026-06-18T10:35:27+00:00

I am grepping through some files look for the string ‘host’ (with the single

  • 0

I am grepping through some files look for the string ‘host’ (with the single quotes). I want to capture the files that have the string without a comment (#).

The test case in the first example works just fine, but the 2nd case below does not. The 2nd case is a test file that I created, and inserted leading spaces in. So I know that there are no control characters, just whitespace.

Both servers are fairly recent versions of Linux.

What could account for the 2nd example not capturing the text? I know I can just grep for host, and then filter with grep -v the comments, but it bugs me that I don’t understand this.

/home/user2> $ cat set.txt
   'host'
/home/user2> $ grep -E "^\s+'host'" set.txt
   'host'

Grep on the other Linux server does not capture the desired data:

[user1@wweb1 ~]$ cat set.txt
     'host'  
[user1@wweb1 ~]$ grep -E "^\s+'host'" set.txt
[user1@wweb1 ~]$
  • 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-18T10:35:28+00:00Added an answer on June 18, 2026 at 10:35 am

    Depending on grep version and type, \s might not work. On my system with grep 2.12, there is no mention of \s, though it does work anyway. Other versions may not have this enabled.

    From the man page:

    The Backslash Character and Special Expressions
       The symbols \< and \>  respectively  match  the  empty  string  at  the
       beginning and end of a word.  The symbol \b matches the empty string at
       the edge of a word, and \B matches the empty string provided  it's  not
       at the edge of a word.  The symbol \w is a synonym for [_[:alnum:]] and
       \W is a synonym for [^_[:alnum:]].
    

    Additionally, man grep | grep "\\\\s" returns nothing at all. And that’s it: no mention of \s.

    Instead, you could use [:space:] as so:

     user@pc $ grep -E "^[[:space:]]+'host'" set.txt
         'host'
    

    So check your grep versions, and go for the syntax that works in all of them. This mailing list post says \s did not work in grep 2.5.1, but did work in 2.6.3, so of you have a pre-2.6.3 version, it might not work with \s.

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

Sidebar

Related Questions

Suppose I have several 200mb+ files that I want to grep through. How would
I'm looking for python modules that can help with grepping C++ code. I have
I have a Apache access.log file, which is around 35GB in size. Grepping through
I am looking for a trick to find included files that are not in
I've got a huge pile of exported emails in .eml format that I'm grepping
I had a question using Perl's readdir(). I want to gather all the files
I want to distinguish between various execution paths in linux kernel so that I
To see all the php files that contain abc I can use this simple
I'm refactoring some code in C++, and I want to deprecate some old methods.
I want to create a new Pivot Item through C# during runtime, displaying a

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.