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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:18:52+00:00 2026-06-04T17:18:52+00:00

I am using the grep -f function to extract lines from a file which

  • 0

I am using the grep -f function to extract lines from a file which match a particular pattern. Let’s say my pattern file is pattern.txt, as follows.

1
2
3
4
5

And the file against which I am matching this pattern is file.txt,

1::anv
2::tyr
3::yui
4::fng
5::gdg
6::ere
7::rer
8::3rr
9::gty

Now when I do a grep -f pattern.txt file.txt, I am getting this ->

1::anv
2::tyr
3::yui
4::fng
5::gdg
8::3rr

The last line in the output above, is causing my problem. How do I modify this grep command so as to get the output (showing correct correspondences) as follows?

1::anv
2::tyr
3::yui
4::fng
5::gdg
  • 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-04T17:18:53+00:00Added an answer on June 4, 2026 at 5:18 pm

    Add ^ before your patterns so that grep will match a line start with your pattern. If your pattern is actually set of numbers, You don’t need a list of patterns. Just use ^[1-5]:.

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

Sidebar

Related Questions

I'm looking for some pattern in 1.txt out of 2.txt, using grep . Then
I am using grep to find out all occurences of a VB function call.
I have been using this so far system 'strings binary-file.dmp | grep search_string' Is
The symbol is in the file. I verified it using nm & grep but
When running a query on SQL Server and using Results to file function, SQL
I am using the $.grep() function http://docs.jquery.com/Utilities/jQuery.grep $.each($.grep( [0,1,2], function(n,i){ return n > 1;
I'm trying to write a grep command that will match a python function declaration,
I'm using a library, which I've loaded into GHCI. From the names of the
Bashing trouble in MSYS: The following simple function should delete all lines that match
Is there an easy way using grep (or combine with other standard command line

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.