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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:30:20+00:00 2026-05-26T19:30:20+00:00

I am having trouble searching for lines with . in complex (chained) grep commands.

  • 0

I am having trouble searching for lines with . in complex (chained) grep commands.
Is this my error or a bug?

grep '\.' filename | grep 1    # works correctly (finds lines with '.' and '1')
grep 1 filename | grep '\.'    # fails: ignores 2nd grep, returns lines with or without '.'

It is not the pipe that causes this; it is really something about grep.
This frankly seems implausible, yet it is true:

cat filename | grep 1 | grep '\.'   # works correctly (and provides an easy work-around for the bug)

Adding more protection does not help:

grep 1 filename | grep '\\.'      # fails

If there is a something behind or in front of the wildcard, it works:

grep 1 filename | grep 'a\.'     #  works
grep 1 filename | grep '\.a'     #  works

But not if the something is a range:

grep 1 filename | grep '[0-9]\.'    # fails
grep 1 filename | grep '\.[0-9]'    # fails

I can’t believe this is really a bug – I must be missing something, right?

Thanks!

uname -a
Linux conception 2.6.32-33-generic #70-Ubuntu SMP Thu Jul 7 21:09:46 UTC 2011 i686 GNU/Linux
  • 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-26T19:30:21+00:00Added an answer on May 26, 2026 at 7:30 pm

    First of all, “chained” grep command is something like “mauvais ton”. Most of times grep | grep can be replaced with one grep with complicated regular expression.

    Grepping lines with . and 1 in it.

    $> cat ./text | grep -P "(\..*1|1.*\.)"
    line with 1 and . in it
    

    -P means perl regex
    "(\..*1|1.*\.)" is (., some symbols and 1) or (1, some symbols and .)

    So, if you not pretty sure about wildcards usage, regular expressions could be your useful, safe, and powerful tool.

    $> cat ./text 
    line without anything
    another line
    line with.ok
    and one another
    line with 1
    some text
    
    line with 1 and . in it
    empty line
    last line
    

    First examples grep '\.' filename | grep 1, grep 1 filename | grep '\.', cat filename | grep 1 | grep '\.' returnes right answer

    line with 1 and . in it
    

    Second example grep 1 filename | grep '\\.' failed because you’re grepping \ with any symbol after it.

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

Sidebar

Related Questions

I've been having trouble searching for this answer because I am not quite sure
I'm not sure what this is called, which is why I'm having trouble searching
I am having trouble getting web services to work in ColdFusion. This works just
I'm having trouble searching for a decent Java library that provides Markov chains, and
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I am having trouble searching a large directory of files for a string. The
I have been having trouble searching through a MySQL table, trying to find entries
I am having trouble searching for what I am looking for. I figure it
I am having some trouble searching for a multiline pattern using regex. Here is

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.