From owner-freebsd-questions@FreeBSD.ORG Tue Dec 23 01:47:29 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E28EF16A4CE for ; Tue, 23 Dec 2003 01:47:29 -0800 (PST) Received: from dire.bris.ac.uk (dire.bris.ac.uk [137.222.10.60]) by mx1.FreeBSD.org (Postfix) with ESMTP id 659DD43D46 for ; Tue, 23 Dec 2003 01:47:28 -0800 (PST) (envelope-from Jan.Grant@bristol.ac.uk) Received: from mail.ilrt.bris.ac.uk by dire.bris.ac.uk with SMTP-PRIV with ESMTP; Tue, 23 Dec 2003 09:47:14 +0000 Received: from cmjg (helo=localhost) by mail.ilrt.bris.ac.uk with local-esmtp (Exim 3.16 #1) id 1AYj6m-0006t2-00; Tue, 23 Dec 2003 09:45:44 +0000 Date: Tue, 23 Dec 2003 09:45:44 +0000 (GMT) From: Jan Grant X-X-Sender: cmjg@mail.ilrt.bris.ac.uk To: Zhang Weiwu In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: Jan Grant cc: freebsd-questions@freebsd.org Subject: Re: How to count the lines of code in a project? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Dec 2003 09:47:30 -0000 On Tue, 23 Dec 2003, Zhang Weiwu wrote: > > Hello. How to count the number of lines in all *.c file in a directory? > > I can think of this on csh: > > > grep -c "" `find . -name "*.c"` | sed "s/.*:/e=e+/" > /tmp/countlines.py > > And edit the py file, and "e=0" as first line, "print e" as the last > line, and execute the python script. wooo pretty cool for a newbie like > me:) > > So is there a better method? Not bad; but when it comes to basic operations on text files, unix has a surfeit of tools that probably already do what you want. In this case: find . -type f -name \*.c -print0 | xargs -0 wc -l -- jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/ Tel +44(0)117 9287088 Fax +44 (0)117 9287112 http://ioctl.org/jan/ (ECHOY GRUNTING) (EERIE WHISPERS) aren't subtitles great?