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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:08:24+00:00 2026-06-10T23:08:24+00:00

I often find myself doing something like this a lot: something | grep cat

  • 0

I often find myself doing something like this a lot:

something | grep cat | grep bat | grep rat

when all I recall is that those three words must have occurred somewhere, in some order, in the output of something…Now, i could do something like this:

something | grep '.*cat.*bat.*rat.*'

but that implies ordering (bat appears after cat). As such, I was thinking of adding a bash function to my environment called mgrep which would turn:

mgrep cat bat rat

into

grep cat | grep bat | grep rat

but I’m not quite sure how to do it (or whether there is an alternative?). One idea would be to for loop over the parameters like so:

while (($#)); do
    grep $1 some_thing > some_thing
    shift
done
cat some_thing

where some_thing is possibly some fifo like when one does >(cmd) in bash but I’m not sure. How would one proceed?

  • 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-10T23:08:25+00:00Added an answer on June 10, 2026 at 11:08 pm

    I believe you could generate a pipeline one command at a time, by redirecting stdin at each step. But it’s much simpler and cleaner to generate your pipeline as a string and execute it with eval, like this:

    CMD="grep '$1' "  # consume the first argument
    shift
    
    for arg in "$@"   # Add the rest in a pipeline
    do
      CMD="$CMD | grep '$arg'"
    done
    eval $CMD
    

    This will generate a pipeline of greps that always reads from standard input, as in your model. Note that it protects spaces in quoted arguments, so that it works correctly if you write:

    mgrep 'the cat' 'the bat' 'the rat'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often find find myself doing a workflow like this: $ find . |grep
I often find myself executing commands like this at bash : history | grep
So I find myself doing something like the following pattern often. Instead of: if
I often find myself doing things like this when manipulating tables:- $($('table tr').children()[2]).html(); For
I often find myself wanting to do something like this, I have something wrapped
I often find myself doing quick checks like this: if (!eregi('.php', $fileName)) { $filename
I find myself doing the following often enough that I feel like there must
Often I find myself coming across code like this: try { StreamWriter strw =
Every now and again I find myself doing something moderately dumb that results in
Ok, I find myself doing this often. I'll attach ids to my tables and

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.