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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:04:54+00:00 2026-06-18T12:04:54+00:00

I would like to grep for the following strings in a file: directory1 directory2

  • 0

I would like to grep for the following strings in a file:

directory1
directory2
directory3

Is there a way to grep for all 3 simultaneously with grep?

For instance:

cat file.txt | grep directory[1-3]

Unfortunately, the above doesn’t work

  • 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-18T12:04:55+00:00Added an answer on June 18, 2026 at 12:04 pm

    If those are the only strings you need to search for, use -F (grep for fixed strings):

    grep -F "directory1
    directory2
    directory3" file.txt
    

    If you want to grep using more advanced regex, use -E (use extended regex):

    grep -E 'directory[1-3]' file.txt
    

    Note that some greps (like GNU grep) won’t require -E for this example to work.

    Finally, note that you need to quote the regex. If you don’t, your shell is liable to expand the regex according to pathname expansion first (e.g. if you have a file/directory called “directory1” in the current directory, grep directory[1-3] will be turned into grep directory1 by your shell).

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

Sidebar

Related Questions

Given a postscript file that has the following header %!PS-Adobe-3.0 I would like to
I would like to call the following bash command in MATLAB: grep Up to
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I would like to add a GestureDetector to all views (view groups) of an
I would like to translate the following Unix 1 Liner to PowerShell. Synopsis of
Hi I would like to wrap the following comma separated data: -X, run, abs,
I would like to check the result of a grep search in a Makefile.
I would like to get an AND -operator to the following Vim command :command!
I have a csv (comma separated file). I would like to know how to
I would like to use Z3Py and I am trying to install Z3 following

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.