From owner-freebsd-hackers Sat Jan 5 13:11:32 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from ussenterprise.ufp.org (ussenterprise.ufp.org [208.185.30.210]) by hub.freebsd.org (Postfix) with ESMTP id CDA5237B429 for ; Sat, 5 Jan 2002 13:11:24 -0800 (PST) Received: (from bicknell@localhost) by ussenterprise.ufp.org (8.11.1/8.11.1) id g05LBOp76469 for freebsd-hackers@FreeBSD.ORG; Sat, 5 Jan 2002 16:11:24 -0500 (EST) (envelope-from bicknell) Date: Sat, 5 Jan 2002 16:11:24 -0500 From: Leo Bicknell To: freebsd-hackers@FreeBSD.ORG Subject: Re: Overriding ARG_MAX Message-ID: <20020105211124.GA76316@ussenterprise.ufp.org> Mail-Followup-To: freebsd-hackers@FreeBSD.ORG References: <200201052048.g05KmeW55815@lurza.secnetix.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200201052048.g05KmeW55815@lurza.secnetix.de> Organization: United Federation of Planets Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Ok, there are several issues here that I just have to point out. :-) In a message written on Sat, Jan 05, 2002 at 09:48:40PM +0100, Oliver Fromme wrote: > ls | grep '\.out$' | wc -l One process shorter: find -name "*.out" -maxdepth 0 | wc -l > ls | grep '\.data$' | xargs grep something Two problems, first use find, second use /dev/null: find -name "*.data" -maxdepth 0 | xargs grep something /dev/null > ls | grep '\.foo$' | xargs cat | grep somethingA A completely unnecessary use of cat. One of the often missed things is the use of /dev/null on grep in this case. If you grep a single file ("grep string file") then it prints the matches. If you grep multiple files ("grep string file1 file2") it prints the matches with the file name prepended. When using xargs, if the number of things to search results in just one being left for the last call to grep you will get all of your results prepended with the file name, except for the last file which will be just the results. Adding /dev/null insures grep always has 2 or more files. Another fix would be: find -name "*.data" -maxdepth 0 | xargs grep -H something I don't believe old grep's had -H though, which is where the /dev/null trick came from. In any event, using find is much better, not so much for this example, but because it allows you to do things like check permissions in a portable way: find -name "*.data" -perm 444 | xargs grep -H something You can't do that with ls | grep, since only the filenames make it to grep. -- Leo Bicknell - bicknell@ufp.org - CCIE 3440 PGP keys at http://www.ufp.org/~bicknell/ Read TMBG List - tmbg-list-request@tmbg.org, www.tmbg.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message