replace
저는 CentOS 서버에서 매우 편리한 명령을 자주 사용합니다 .
바꾸기 유틸리티 프로그램은 파일이나 표준 입력의 문자열을 변경합니다.
RPM 측면에서도 독립형 패키지는 아니며 더 큰 유틸리티 패키지의 일부라고 생각합니다. 어쨌든, 이것에 상응하는 우분투가 있는지 궁금합니다. 나는 grep
and 를 가지고 놀 수 있다는 것을 알고 있지만 sed
훨씬 replace
더 편리합니다.
답변1
이것은 이미 Red Hat/CentOS의 일부인 앱이기 때문에 rpm 파일을 설치하는 데 replace 2.24
사용하는 소스가 아닌 대체 방법입니다 .alien
터미널 창에 다음 줄을 자유롭게 복사하여 붙여넣으세요.
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
그런 다음 새 앱을 실행하세요.
$ 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.
도움이 되었기를 바랍니다!
답변2
mariadb-server-10.1
및 패키지 mysql-server-5.7
에는 percona-xtradb-cluster-server-5.7
버전이 포함되어 있지만 replace
이러한 버전은 대부분 오래된 것으로 보이며 일부 버전은 더 이상 사용되지 않습니다.
소프트웨어에는 다음과 같은 웹사이트가 있습니다.https://replace.richardlloyd.org.uk, 안타깝게도 다운로드 링크가 깨졌으나 다음에서 최신 버전(현재 2.24)을 파일로 다운로드할 수 있습니다 .tar.gz
.여기: 아래로 끝까지 스크롤하여 마지막 줄에서 “HTTP”를 선택합니다. replace
이 파일에서 설치하려면 다음 단계를 따르세요 .
아카이브를 추출합니다
.tar.gz
.tar xf replace-*.tar.gz
다음 디렉토리로 변경합니다.
cd replace-*/
설치에는 가 필요
gmake
하지만 Ubuntu에서 호출되므로make
심볼릭 링크를 만듭니다.sudo ln -s /usr/bin/make /usr/bin/gmake
달리다
gmake
:gmake
의 shebang을
tests/runtests
다음으로 변경합니다( 없는 를 사용bash
하기 때문에 ).let
sh
sed '1s/sh/bash/' tests/runtests
테스트를 실행합니다.
gmake test
다음 위치에 소프트웨어를 설치합니다
/usr/local/bin/replace
.sudo gmake install
설치가 완료되면 디렉토리 및 파일 /usr/bin/gmake
뿐만 아니라 심볼릭 링크도 제거할 수 있습니다 .replace-N.NN/
.tar.gz
cd .. && rm -r replace-*/ replace-*.tar.gz && sudo rm /usr/bin/gmake