From owner-freebsd-questions@FreeBSD.ORG Wed Jan 11 20:24:29 2006 Return-Path: X-Original-To: questions@freebsd.org 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 1650C16A41F for ; Wed, 11 Jan 2006 20:24:29 +0000 (GMT) (envelope-from vaaf@broadpark.no) Received: from osl1smout1.broadpark.no (osl1smout1.broadpark.no [80.202.4.58]) by mx1.FreeBSD.org (Postfix) with ESMTP id 208D143D55 for ; Wed, 11 Jan 2006 20:24:27 +0000 (GMT) (envelope-from vaaf@broadpark.no) Received: from broadpark.no ([217.13.4.96]) by osl1smout1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0ISY00LS63L81540@osl1smout1.broadpark.no> for questions@freebsd.org; Wed, 11 Jan 2006 21:29:32 +0100 (CET) Received: from [80.202.4.61] (Forwarded-For: [213.187.181.70]) by bgo1mstore1.broadpark.no (mshttpd); Wed, 11 Jan 2006 21:24:35 +0100 Date: Wed, 11 Jan 2006 21:24:35 +0100 From: Kristian Vaaf To: questions@freebsd.org Message-id: MIME-version: 1.0 X-Mailer: Sun Java(tm) System Messenger Express 6.1 HotFix 0.05 (built Oct 21 2004) Content-type: text/plain; charset=us-ascii Content-language: en Content-transfer-encoding: 7BIT Content-disposition: inline X-Accept-Language: en Priority: normal Cc: Subject: My script to replace strings in ASCII files X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jan 2006 20:24:29 -0000 Hello! Just curious, what do I need to do to be able to execute this script like: $ text-replace old_string new_string I find it a bit inconvenient having to edit the script for every thing I need to replace. Thanks, Kristian #!/usr/local/bin/bash # # Replace old with new inside all text files. # $URBAN: text-replace.sh,v 1.0 2005/10/24 15:09:05 vaaf Exp $ # for file in `find . -type f ! -name ".*"`; do if [ "`file -b "$file" | grep text`" != "" ]; then sed -i '' "s/old/new/g" "$file" echo "$file: Done" fi done