Costumo usar o replace
comando muito útil em meu servidor CentOS:
O programa utilitário de substituição altera as strings nos arquivos ou na entrada padrão.
Não é um pacote independente, mesmo no lado RPM, acho que faz parte de um pacote de utilitários maior. De qualquer forma, estou me perguntando se existe um Ubuntu equivalente a isso? Eu sei que posso brincar com grep
e sed
, mas replace
é muito mais conveniente.
Responder1
Esta é uma forma alternativa replace 2.24
que não é do código-fonte alien
para instalar o arquivo rpm, pois este é um aplicativo que já faz parte do Red Hat / CentOS.
Sinta-se à vontade para copiar e colar as seguintes linhas em uma janela de terminal.
cd /tmp
sudo apt install alien
wget https://extras.getpagespeed.com/redhat/7/x86_64/RPMS/replace2-2.24-1.el7.x86_64.rpm
sudo alien replace2-2.24-1.el7.x86_64.rpm
sudo dpkg -i replace2_2.24-2_amd64.deb
Em seguida, execute o novo aplicativo
$ replace2
replace 2.24 (C) Richard K. Lloyd 2004 - The sane person's alternative to sed
Syntax: replace2 [-?] [-A] [-b] [-c startcol] [-d tempdir] [-e] [-f]
[-h] [-i] [-L] [-l linenum] [-m maxreplines] [-n] [-P] [-p]
[-r|R] [-s] [-T] [-t maxtimes] [-u backupsuffix] [-v]
[-w] [-x suffix [-x...]] [-z]
old_str new_str [-a old_str new_str...] [filename...]
-? displays this syntax message.
-A forces the program to assume all files are text files. Normally, the first
256 bytes are examined to auto-determine if a file is text or binary.
This option is deprecated and may be changed or removed in a future release.
-a allows extra pairs of strings to be replaced in order.
-b forces the program to assume all files are binary files.
-c startcol starts the string replace from column 'startcol' rather than the
first column.
-d specifies the temporary directory for storing modified files. If not
supplied, the default directory is $TMPDIR or, if that isn't set, /tmp.
-e makes search case-sensitive. new_str exactly replaces old_str
with no case-adjustment to new_str.
-f forces the update of files without any .cln backup.
-h indicates that replacement pairs are binary hex data.
-i interactively prompts the user to confirm if they want strings replaced in
next file. Specifying -i -i switches to prompting for each replacement.
-L follows soft-links specified on the command line.
-l linenum starts the string replacement from line 'linenum' rather than the
first line.
-m maxreplines specifies the maximum number of lines in a file that should
have string replacements.
-n displays what strings would be replaced without actually replacing them.
It also switches on verbose mode.
-P pre-pads new_str with leading spaces if it is shorter than old_str.
-p pads new_str with trailing spaces if it is shorter than old_str.
-r or -R recurses down the current directory tree (if no filenames are given),
replacing strings in all files found. Use -x to narrow the recursion.
-s relaxes the condition that old_str has to match a 'word' i.e. it replaces
old_str even if it is a substring of a 'word'.
-T retains the timestamps of the original unmodified files.
-t maxtimes states the maximum number of times a string can be replaced
in any single line of a file.
-u backupsuffix specifies the backup suffix for the unmodified file.
-v increments (switches on) verbose mode, reporting a summary of replacements
if specified once and all replacements if specified twice (i.e. -vv).
-w recursively replaces strings in all Web-related source files in the current
directory tree. Equivalent to "-r -x .html -x .htm -x .asp -x .js -x .css
-x .xml -x .xhtml -x .shtml -x .jsp -x .php -x .php3 -x .php4 -x .pl".
-x suffix specifies a case-insensitive filename suffix to look for when
recursing. Multiple -x params can be supplied and have an "or" meaning.
-z Zero-terminate any binary replacement string.
Espero que isto ajude!
Responder2
Os pacotes mariadb-server-10.1
, mysql-server-5.7
e percona-xtradb-cluster-server-5.7
contêm versões do replace
, mas essas versões parecem ser em sua maioria antigas e algumas estão até obsoletas.
O software possui um site chamadohttps://replace.richardlloyd.org.uk, infelizmente o link de download está quebrado, mas você pode baixar a versão mais recente (atualmente 2.24) como um .tar.gz
arquivo emaqui: Role totalmente para baixo e selecione “HTTP” na última linha. Siga estas etapas para instalar replace
a partir deste arquivo:
Extraia o
.tar.gz
arquivo:tar xf replace-*.tar.gz
Mude para o diretório:
cd replace-*/
A instalação precisa
gmake
, mas é chamadamake
no Ubuntu, então crie um link simbólico:sudo ln -s /usr/bin/make /usr/bin/gmake
Correr
gmake
:gmake
Mude o shebang de
tests/runtests
parabash
(porque usalet
, quesh
não possui):sed '1s/sh/bash/' tests/runtests
Execute os testes:
gmake test
Instale o software para
/usr/local/bin/replace
:sudo gmake install
Depois de instalado, você pode remover o /usr/bin/gmake
link simbólico, bem como o replace-N.NN/
diretório e o .tar.gz
arquivo:
cd .. && rm -r replace-*/ replace-*.tar.gz && sudo rm /usr/bin/gmake