OFFTOPIC: search and replace with unix tools

Поиск
Список
Период
Сортировка
От Oliver Seidel
Тема OFFTOPIC: search and replace with unix tools
Дата
Msg-id lfsnihtcmx.fsf@delta.imr-dvlp.de
обсуждение исходный текст
Ответ на Need help with search-and-replace  ("Josh Berkus" <josh@agliodbs.com>)
Список 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 по дате отправления:

Предыдущее
От: "Josh Berkus"
Дата:
Сообщение: Re: calling a function within a view causes problems doing a pg_dumpall
Следующее
От: Kyle
Дата:
Сообщение: Re: RI permission problem