OFFTOPIC: search and replace with unix tools

From: Oliver Seidel <seidel(at)in-medias-res(dot)com>
To: "Josh Berkus" <josh(at)agliodbs(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: OFFTOPIC: search and replace with unix tools
Date: 2001-05-07 15:14:14
Message-ID: lfsnihtcmx.fsf@delta.imr-dvlp.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>>>>> "Josh" == Josh Berkus <josh(at)agliodbs(dot)com> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Radius Administrator 2001-05-07 16:10:50 INT8 sequences
Previous Message Josh Berkus 2001-05-07 14:53:49 Re: calling a function within a view causes problems doing a pg_dumpall