From owner-freebsd-questions@FreeBSD.ORG Mon Dec 22 04:11:30 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ECE1A106564A for ; Mon, 22 Dec 2008 04:11:30 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id ACEFA8FC19 for ; Mon, 22 Dec 2008 04:11:30 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r55.edvax.de (port-92-196-14-53.dynamic.qsc.de [92.196.14.53]) by mx02.qsc.de (Postfix) with ESMTP id 7220216C01B1; Mon, 22 Dec 2008 05:11:27 +0100 (CET) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id mBM4B3qg006716; Mon, 22 Dec 2008 05:11:03 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Mon, 22 Dec 2008 05:11:03 +0100 From: Polytropon To: Giorgos Keramidas Message-Id: <20081222051103.79a822e6.freebsd@edvax.de> In-Reply-To: <87skogj37n.fsf@kobe.laptop> References: <20081221053407.GA87868@thought.org> <877i5unkx4.fsf@kobe.laptop> <1229854084.6392.52.camel@ethos> <20081221140658.GA24691@marge.bs.l> <20081221222744.GA28185@thought.org> <87skogj37n.fsf@kobe.laptop> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: Gary Kline , freebsd-questions@freebsd.org Subject: Re: Sed question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Dec 2008 04:11:31 -0000 On Mon, 22 Dec 2008 05:31:08 +0200, Giorgos Keramidas wrote: > On Sun, 21 Dec 2008 14:27:44 -0800, Gary Kline wrote: > > perl -pi.bak -e 's/OLDSTRING/NEWSTRING/g' file1 file2 fileN > > > > that i swiped somewhere. [?] > > > > last night i was up until the wee hours coding or extending > > a c++ program to assist in this stuff. while i really get > > off on hacking code, it's less of a thrill at 02:10, say:_) > > You don't need C++ for this. If you don't mind the verbosity, Python > can do the same thing with: > > #!/usr/bin/env python > > import sys > > skiplines = [1, 3] # line numbers that should be skipped > lc = 0 > for l in sys.stdin.readlines(): > lc += 1 > if not (lc in skiplines): > print l, > Interesting example. The same could be achieved using awk: awk '(NR != 1 && NR != 3)' NR specifies the number of record (input line). But I still think the sed in-place editing method is the most comfortable one, allthough your example raises my interest in learning Python. -- Polytropon >From Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...