Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-13-2005, 10:48 AM   #1
LQ Newbie
Registered: Jan 2005
Posts: 2

Rep: Reputation: 0
bash script and grep

Hi everyone, i have to do a little script that search files that contains a string, and print the name of thoose files on the screen. Also, it must allow the user to see only the x first or last results. The script is already done and works well, but it is giving a strange message when asking only for the first x results.

For this cas i use this command:
find /usr/include/ -name "*" -print | xargs grep -s -l $1 |  head -n $3
so when i run
 ./ class + 3
to get the 3 first results i get this:
xargs: grep: terminated by signal 13
Does anyone know what i have to do so that the xargs message doensn't appear?

It seems it happens cause head ends the grep process.

Well, thanks in advance.
Old 01-13-2005, 11:07 AM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 58
find /usr/include/ -name "*" -print | xargs grep -s -l $1 | head -n $3
Try changing $3 to just 3
Old 01-13-2005, 11:14 AM   #3
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,371

Rep: Reputation: 192Reputation: 192
incidentally you don't need -name '*'

blah/blah blah |  2>/dev/null xargs grep | head
though i don't like this solution much.

interesting point though.
Old 01-13-2005, 11:21 AM   #4
LQ Newbie
Registered: Jan 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Thumbs up

Many thanks, that worked perfectly!
Old 01-13-2005, 04:04 PM   #5
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,571

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
incidentally, you do not need "-print" either ...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to grep similar lines in bash? bruno buys Linux - Software 2 12-03-2005 12:56 AM
Bash script question (grep and awk) hamish Linux - Software 6 04-06-2005 04:14 PM
Bash assignment - using a grep inside an if statement lowpro2k3 Programming 4 03-25-2005 06:24 PM
newbe bash question ( grep processing) therealbxp Programming 2 11-20-2004 08:40 AM
bash command: grep mAineAc Programming 6 11-18-2004 12:00 PM

All times are GMT -5. The time now is 05:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration