From: Oliver Seidel <seidel@in-medias-res.com>
To: Josh Berkus <josh@agliodbs.com>
Cc: pgsql-sql@postgresql.org
Subject: OFFTOPIC: search and replace with unix tools
Date: 07 May 2001 17:14:14 +0200
Message-ID: <lfsnihtcmx.fsf@delta.imr-dvlp.de> (raw)
References: <web-52032@davinci.ethosmedia.com>
>>>>> "Josh" == Josh Berkus <josh@agliodbs.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: seidel@in-medias-res.com, josh@agliodbs.com
Subject: Re: OFFTOPIC: search and replace with unix tools
In-Reply-To: <lfsnihtcmx.fsf@delta.imr-dvlp.de>
References: <web-52032@davinci.ethosmedia.com> <lfsnihtcmx.fsf@delta.imr-dvlp.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox