From owner-freebsd-questions@FreeBSD.ORG Sun May 20 16:22:46 2012 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 9FD31106566C for ; Sun, 20 May 2012 16:22:46 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) by mx1.freebsd.org (Postfix) with ESMTP id 5D0E58FC14 for ; Sun, 20 May 2012 16:22:46 +0000 (UTC) Received: from r56.edvax.de (port-92-195-20-192.dynamic.qsc.de [92.195.20.192]) by mx01.qsc.de (Postfix) with ESMTP id 8D9903CA34; Sun, 20 May 2012 18:22:45 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id q4KGMjtl003365; Sun, 20 May 2012 18:22:45 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sun, 20 May 2012 18:22:45 +0200 From: Polytropon To: Tim Dunphy Message-Id: <20120520182245.b04d681f.freebsd@edvax.de> In-Reply-To: References: Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-questions Subject: Re: eliminate character with sed 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: Sun, 20 May 2012 16:22:46 -0000 On Sun, 20 May 2012 12:08:04 -0400, Tim Dunphy wrote: > Hello list, > > I have a few php config files that have the windows delimiter > character in them ('^M') that I would like to get rid of. I'm trying > to use sed to do it, and for some reason I am not having any luck. > > Here's the line that I'm trying to use: > > #sed -i '.bak' 's/^M//g' config.php > > However when I have a look at the backup file that's been created with > this command, it looks like there was no effect: > > define('DS',DIRECTORY_SEPARATOR);^M^M > if(!defined("_MAINSITEPATH_"))^M > define("_MAINSITEPATH_",dirname(__FILE__).DS);^M > > I was wondering is someone had a tip on how to run this command > effectively in this situation. It seems that you need proper quoting. The character sequence "^M" != ASCII code of CR. Note that ^M is just a _visual representation_ of Ctrl-M, which does output the same ASCII code as the "CR key" would. The corresponding escape sequence is \r. Together with \n, the DOS-based "line end" \r\n is generated. Remove the \r part, and you have the default (normal) line end - as you correctly intended. Note that different viewers or editors might have a different representation than "^M"! As you just want to delete the ^M (the CR), why not use "tr" instead? % tr -d '\r' < config.php > config.php.new Put a bit of scripting around it, and it will do the same. See "man tr" for details. Regarding the use of "sed": I'm not sure if it's possible to do something like % sed -i '.bak' 's/\r//g' config.php because I assume (not tested!) that it's not possible to put in escape sequences like that. But try for yourself and surprise me. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...