LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-13-2005, 09:48 AM   #1
syros
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:
Code:
find /usr/include/ -name "*" -print | xargs grep -s -l $1 |  head -n $3
so when i run
Code:
 ./script.sh class + 3
to get the 3 first results i get this:
Code:
/usr/include/awk/regex.h
/usr/include/awk/regex_internal.h
/usr/include/net/route.h
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, 10:07 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

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

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

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


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

Original Poster
Rep: Reputation: 0
Thumbs up

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

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


Reply


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-02-2005 11:56 PM
Bash script question (grep and awk) hamish Linux - Software 6 04-06-2005 03:14 PM
Bash assignment - using a grep inside an if statement lowpro2k3 Programming 4 03-25-2005 05:24 PM
newbe bash question ( grep processing) therealbxp Programming 2 11-20-2004 07:40 AM
bash command: grep mAineAc Programming 6 11-18-2004 11:00 AM


All times are GMT -5. The time now is 02:00 AM.

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