OFFTOPIC: search and replace with unix tools - Mailing list pgsql-sql

From Oliver Seidel
Subject OFFTOPIC: search and replace with unix tools
Date
Msg-id lfsnihtcmx.fsf@delta.imr-dvlp.de
Whole thread Raw
In response to Need help with search-and-replace  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
>>>>> "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
anyUnix-based   Josh> tool to search-and-replace a specific value which includes a   Josh> tab character (e.g. replace
"{TAB}700: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


pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: calling a function within a view causes problems doing a pg_dumpall
Next
From: Kyle
Date:
Subject: Re: RI permission problem