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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:07:10+00:00 2026-05-25T20:07:10+00:00

For sometime I have been trying to play with grep to retrieve data from

  • 0

For sometime I have been trying to play with grep to retrieve data from files and I noticed something funny.

It might be my ignorance but here is what happens…

Suppose I have a file ABC. the data is:

a
abc
ab
bac
bb
ac

Now ran this grep command,

grep a* ABC

I found the output to contain lines starting a with b.c. why is this happening?

  • 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-25T20:07:10+00:00Added an answer on May 25, 2026 at 8:07 pm

    You used ‘a*’ as your search pattern… the ‘*’ means ZERO or MORE of the previous character, so ‘b.c’ matches, having ZERO or more ‘a’s in it.

    On a semi-related note, I’d recommend quoting the ‘a*’ bit, since if you have ANY files in the current subdirectory which start with a, you’ll be VERY surprised to see what you’re really searching for, since the shell (bash,zsh,csh,sh,dash,wtfsh…) will perform wildcard expansion automatically BEFORE the command is executed.

    if you want to search for lines which START with ‘a’, then you’ll need to anchor the search pattern with a leading ^ character, so your pattern becomes ‘^a*’, but again, the * means ZERO or more, so it’s not useful in this situation where you only have one letter… use ‘^a’ instead.

    As a contrived example, if you wanted to find all the lines containing a ‘c’ AND those containing the letters ‘bc’, then you could use ‘b*c’ as the search pattern… meaning ZERO or more b’s, and a c.

    The power of the regex search pattern is immense, and takes some time to grok. Peruse the man pages for grep(1), regex(7), pcre(3), pcresyntax(3), pcrepattern(3).

    Once you get the hang of them, regex’s are useful in sed, grep, perl, vim, (probably emacs too), … uh, it’s late (early?) nothing more comes to mind, but they’re VERY powerful.

    As some bonus, ‘*’ means ZERO or more, ‘+’ means ONE or more, and ‘?’ means ZERO or ONE.

    So to search for things with two or more a’s… ‘aa+’, which is 1 a, and 1+ a (1 or more)

    I ramble…. (regex(7)!)

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

Sidebar

Related Questions

I have been have issues trying to retrieve the values from a treeMap that
I have been trying to figure this out for quite sometime (reading online blogs
For sometime now, I have been trying to wrap my head around the reason
I have been trying out ilog jrules for sometime now.I especially interested in rule
I'm new to Scheme, have been using MIT Scheme for sometime now. I'm trying
I have been working with WebServices for sometime. I dealt with many services where
i have been programming for sometime but all of my programming books have not
i have been programing in vc++ for sometime and i want to make some
I have been working with relational databases for sometime, but it only recently occurred
I have been writing web applications for quite sometime in PHP with MySQL. I

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.