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

  • Home
  • SEARCH
  • 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 9030805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:34:55+00:00 2026-06-16T07:34:55+00:00

bash guru ;) I’m trying to improve some string in bash which grep specific

  • 0

bash guru 😉 I’m trying to improve some string in bash which grep specific keyword’s matches in specific files. It looks like that:

find /<path>/hp -iname '*.ppd' -print0 | xargs -0 grep "\*ModelName\:"

which works very fast for me! In 20 times faster than this one:

find /<path>/hp -iname '*.ppd' -print0 | xargs -0 -I {} bash -c 'grep "\*ModelName\:" {}'

But the problem is that in the first script I’m getting the following lines:

/<path>/hp/hp-laserjet_m9040_mfp-ps.ppd:*ModelName: "HP LaserJet M9040 M9050 MFP"

but desired result is just

*ModelName: "HP LaserJet M9040 M9050 MFP"  

(as in the second script). How can I achieve it?

P.S.: I’m using find for flexibility and future improvements of the script.

  • 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-16T07:34:56+00:00Added an answer on June 16, 2026 at 7:34 am

    The -h option to grep suppress filenames from the output.

    find /<path>/hp -iname '*.ppd' -print0 | xargs -0 grep -h "\*ModelName\:"
    

    If your grep does not provide -h the use cat:

    find /<path>/hp -iname '*.ppd' -print0 | xargs -0 cat | grep "\*ModelName\:"
    

    Also, for your information, find provides the -exec option which would render xargs unnecessary had you wanted to pursue your second option:

    find /<path>/hp -iname '*.ppd' -exec grep grep "\*ModelName\:" '{}' \;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On bash, I have the following (typical) scenario: ~/some/dir$ find | grep java which
Note: Bash 3.00 How to substitute this example string 123456789 , to look like
My bash script looks like: read -p Do you wish to continue? yn #
In Bash I can use printf to format a string output like this:- (Note
#!/bin/bash # . ~/some_env database_name The code looks just like the above, and every
In bash I'm trying to collect my grep results in array, each cell holding
Bash how do you capture stderr to a variable? I would like to do
Setup: Bash Ruby 1.9.2 highline (1.6.13) Description: I'm fairly used to highline with some
Using bash, how can one get the number of files in a folder, excluding
In Bash, how do I declare a local integer variable, i.e. something like: func()

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.