Received: from imr-int.intra.in-medias-res.com (fw.in-medias-res.com [62.154.153.2]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f47FEKA37212 for ; Mon, 7 May 2001 11:14:20 -0400 (EDT) (envelope-from os10000@in-medias-res.com) Received: from [192.168.2.234] (helo=alpha.imr-dvlp.de ident=root) by imr-int.intra.in-medias-res.com with esmtp (Exim 3.13 #1) id 14wmiF-0007x9-00; Mon, 07 May 2001 17:14:15 +0200 Received: from delta.imr-dvlp.de (delta.imr-dvlp.de [192.168.7.4]) by alpha.imr-dvlp.de (8.9.3/8.9.3) with SMTP id RAA22201; Mon, 7 May 2001 17:14:14 +0200 Received: by delta.imr-dvlp.de via sendmail with stdio id for josh@agliodbs.com; Mon, 7 May 2001 17:14:14 +0200 (CEST) (Smail-3.2 1996-Jul-4 #1 built 2000-Jul-29) To: "Josh Berkus" Cc: pgsql-sql@postgresql.org Subject: OFFTOPIC: search and replace with unix tools References: Reply-To: seidel@in-medias-res.com X-URL: http://www.cl.cam.ac.uk/users/os10000/ X-Face: 83&"QxvYR7rv.OhJ1c-R;^dHI|nlib0{?5QyuJp1yD\52 >{J+eR0C|p(,/i1_w(gGFE|U9Gi>-PL>.Zy\ Date: 07 May 2001 17:14:14 +0200 In-Reply-To: "Josh Berkus"'s message of "Sat, 05 May 2001 15:27:22 -0700" Message-ID: Lines: 34 X-Mailer: Gnus v5.7/Emacs 20.7 X-Archive-Number: 200105/46 X-Sequence-Number: 2847 >>>>> "Josh" == Josh Berkus writes: Josh> Folks, I need to strip certain columns out of my pgdump Josh> file. However, I can't figure out how to use any Unix-based Josh> tool to search-and-replace a specific value which includes a Josh> tab character (e.g. replace "{TAB}7 00:00:00" with "" to Josh> eliminate the column). Unix lives by the shell pipe. Set "exit on error", to avoid data loss in case of "filesystem full", proceed by using "tr" to translate single characters within the file to something more easily replacable, do the replace with "sed", translate back using "tr", move over old file, done: --------------------------------------------------------------------------- #!/bin/bash set -e -x cat "$*" | \ tr '\t' '§' | \ sed -e 's/§7 00:00:00//g' | \ tr '§' '\t' | \ cat > x.$$ mv x.$$ "*" --------------------------------------------------------------------------- (please don't kill me for the two "cat" operators, they serve no purpose besides legibility). so long, Oliver