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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:08:46+00:00 2026-06-11T22:08:46+00:00

I am stuck on the last step and hope someone could help me out.

  • 0

I am stuck on the last step and hope someone could help me out.

I have 2 files:

file1 =

Green Apple

file2 =

Green Apple/quantity/100

Red Peach/quantity/200

My code:

grep -f file1 file2 | sed ‘s/quantity(.*)/totalXYZ/’

= Green Apple/totalXYZ

I would like to apply it to file2 so the result would look like this:

file2 =

Green Apple/totalXYZ

Red Peach/quantity/200

Thanks

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

    You can get it using AWK this way:

    awk -f grepandreplace.awk file2 file1
    

    The code of “grepandreplace.awk” is:

    #!/usr/bin/awk -f
    BEGIN {
        FS = "/";
        f_grep = ARGV[2];
        ARGC = 2;
    
        while ((getline < f_grep) > 0) {
            grep[$1] = "";
        }
    }
    
    {
        if ($1 in grep) {
            print $1"/totalXYZ";
        } else {
            print $0;
        }
    }
    

    And I got your desired output:

    Green Apple/totalXYZ
    Red Peach/quantity/200
    

    Any questions? leave me a comment.

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

Sidebar

Related Questions

Can anyone please help me out.I have been stuck with this NSMutableArray for last
I have been stuck for the last couple of days deploying a standard WAR
I almost have this Powershell script completed but I am stuck at the last
I'm a bit stuck on the last step of getting the solution to problem
I'm converting a code from C to Delphi, but I'm stuck on the last
I am stuck with facebook authentication for the last 5 hours now and I
I am stuck here and i spend last 2 days resolving this issue but
I've been stuck with this simple Sql query for last 3 hours and my
H e l l o Everyone, after installing the last Xcode 4.3.1 I stuck
I'm using bValidator plugin on my local website, and I'm stuck with the last

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.