进行备份后,在文件中进行搜索和替换

.

0

linux命令:perl -i'.bak' -pe 's/old/new/g' <filename> <filename> 's/old/new/g' -pe -i'.bak' perl perl -i'.bak' -pe 's/old/new/g' <filename>rootopen.com
linux命令:perl -i'.bak' -pe 's/old/new/g' <filename> <filename> 's/old/new/g' -pe -i'.bak' perl perl -i'.bak' -pe 's/old/new/g' <filename>rootopen.com
vghh 2018-01-20 11:51:48
输出
替代方案1 进行备份后,在文件中进行搜索和替换

sed已经有一个选项来编辑文件并制作旧文件的备份副本。 -i将编辑一个文件,如果你给它一个参数,它会使用该字符串作为扩展名创建一个备份文件。.

linux命令:sed -i.bak 's/old/new/g' file file 's/old/new/g' -i.bak sed sed -i.bak 's/old/new/g' filerootopen.com
linux命令:sed -i.bak 's/old/new/g' file file 's/old/new/g' -i.bak sed sed -i.bak 's/old/new/g' filerootopen.com
.
输出
替代方案2 进行备份后,在文件中进行搜索和替换

当且仅当已完成备份和/ bin / cp干净地退出时,“&&”才运行sed。适用于多个文件;只需指定多个文件名(或glob)。使用-v切换cp可以安全地播放它。.

linux命令:for file in <filename>; do cp $file{,.bak} && sed 's/old/new/g' $file.bak > $file; done done $file; > $file.bak 's/old/new/g' sed && $file{,.bak} cp do <filename>; in file for for file in <filename>; do cp $file{,.bak} && sed 's/old/new/g' $file.bak > $file; donerootopen.com
linux命令:for file in <filename>; do cp $file{,.bak} && sed 's/old/new/g' $file.bak > $file; done done $file; > $file.bak 's/old/new/g' sed && $file{,.bak} cp do <filename>; in file for for file in <filename>; do cp $file{,.bak} && sed 's/old/new/g' $file.bak > $file; donerootopen.com
.
输出

评论

相关推荐

-n在循环中逐行读取输入,发送到$_ Equivalent to while () { mycode } -e execute执行以下引用的字符串(即在与perl命令相同的行上执行以下操作)elipses ..运算符表现得像一个范围,从一行到另一行记住状态。

linux命令:perl -ne 'print if /start_pattern/../stop_pattern/' file.txt file.txt /start_pattern/../stop_pattern/' if 'print -ne perl perl -ne 'print if /start_pattern/../stop_pattern/' file.txtrootopen.com
linux命令:perl -ne 'print if /start_pattern/../stop_pattern/' file.txt file.txt /start_pattern/../stop_pattern/' if 'print -ne perl perl -ne 'print if /start_pattern/../stop_pattern/' file.txtrootopen.com
.

最后的“g”是全球性的,意思是替换所有的事件,而不仅仅是第一个。

linux命令:perl -pi -e's/foo/bar/g' file1 file2 fileN fileN file2 file1 -e's/foo/bar/g' -pi perl perl -pi -e's/foo/bar/g' file1 file2 fileNrootopen.com
linux命令:perl -pi -e's/foo/bar/g' file1 file2 fileN fileN file2 file1 -e's/foo/bar/g' -pi perl perl -pi -e's/foo/bar/g' file1 file2 fileNrootopen.com
.

将“.bk”添加到常规的“pie”成语中会使perl为每个带有“.bk”扩展名的文件创建一个备份,以防它返回某些内容并且希望它返回

linux命令:perl -pi.bk -e's/foo/bar/g' file1 file2 fileN fileN file2 file1 -e's/foo/bar/g' -pi.bk perl perl -pi.bk -e's/foo/bar/g' file1 file2 fileNrootopen.com
linux命令:perl -pi.bk -e's/foo/bar/g' file1 file2 fileN fileN file2 file1 -e's/foo/bar/g' -pi.bk perl perl -pi.bk -e's/foo/bar/g' file1 file2 fileNrootopen.com
.

在指定的所有文件中替换“新”的所有“旧”事件。 'i'字符之后,你可以放一个'〜'或者其他的来创建一个备份文件,每个备份文件替换为与原始加字符相同的名称。

linux命令:perl -i -pe "s/old/new/g" * * "s/old/new/g" -pe -i perl perl -i -pe "s/old/new/g" *rootopen.com
linux命令:perl -i -pe "s/old/new/g" * * "s/old/new/g" -pe -i perl perl -i -pe "s/old/new/g" *rootopen.com
.

linux命令:perl -pi -e 's/localhost/replacementhost/g' *.php *.php 's/localhost/replacementhost/g' -e -pi perl perl -pi -e 's/localhost/replacementhost/g' *.phprootopen.com
linux命令:perl -pi -e 's/localhost/replacementhost/g' *.php *.php 's/localhost/replacementhost/g' -e -pi perl perl -pi -e 's/localhost/replacementhost/g' *.phprootopen.com
.

Bork,bork,bork!为了保持简短,第一条终端线路不显示提示。

linux命令:perl -e '$b="bork"; while(<STDIN>){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; print "$l$b\@$b:\$ ";}' ";}' "$l$b\@$b:\$ print $l=~s/[A-Za-z]+/$b/g; 2>&1`; while(<STDIN>){$l=`$_ '$b="bork"; -e perl perl -e '$b="bork"; while(<STDIN>){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; print "$l$b\@$b:\$ ";}'rootopen.com
linux命令:perl -e '$b="bork"; while(<STDIN>){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; print "$l$b\@$b:\$ ";}' ";}' "$l$b\@$b:\$ print $l=~s/[A-Za-z]+/$b/g; 2>&1`; while(<STDIN>){$l=`$_ '$b="bork"; -e perl perl -e '$b="bork"; while(<STDIN>){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; print "$l$b\@$b:\$ ";}'rootopen.com
.

在所有匹配fileglob *的文件中将THIS更改为THAT,而不使用辅助文件

linux命令:perl -pi -e 's/THIS/THAT/g' fileglob* fileglob* 's/THIS/THAT/g' -e -pi perl perl -pi -e 's/THIS/THAT/g' fileglob*rootopen.com
linux命令:perl -pi -e 's/THIS/THAT/g' fileglob* fileglob* 's/THIS/THAT/g' -e -pi perl perl -pi -e 's/THIS/THAT/g' fileglob*rootopen.com
.

对来自输入(文件或标准输入)的HTML实体进行编码,因此可以直接将结果传递到博客或HTML源文件。

linux命令:perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txt /tmp/subor.txt encode_entities($_)' 'print -ne -MHTML::Entities perl perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txtrootopen.com
linux命令:perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txt /tmp/subor.txt encode_entities($_)' 'print -ne -MHTML::Entities perl perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txtrootopen.com
.

连接多行,以逗号分隔值创建单行。例如,如果我们每行都有一个电子邮件地址(从电子表格复制并粘贴),则它将输入一行与comman分隔的地址以将其放到电子邮件客户端。

linux命令:perl -le 'print join ", ", map { chomp; $_ } <>' <>' } $_ chomp; { map ", ", join 'print -le perl perl -le 'print join ", ", map { chomp; $_ } <>'rootopen.com
linux命令:perl -le 'print join ", ", map { chomp; $_ } <>' <>' } $_ chomp; { map ", ", join 'print -le perl perl -le 'print join ", ", map { chomp; $_ } <>'rootopen.com
.

linux命令:perl -pe 's/.+;//' ~/.zsh_history | sort | uniq -c | sort -r|head -10 -10 -r|head sort | -c uniq | sort | ~/.zsh_history 's/.+;//' -pe perl perl -pe 's/.+;//' ~/.zsh_history | sort | uniq -c | sort -r|head -10rootopen.com
linux命令:perl -pe 's/.+;//' ~/.zsh_history | sort | uniq -c | sort -r|head -10 -10 -r|head sort | -c uniq | sort | ~/.zsh_history 's/.+;//' -pe perl perl -pe 's/.+;//' ~/.zsh_history | sort | uniq -c | sort -r|head -10rootopen.com
.

快速命令检查服务器上是否安装了Perl库。

linux命令:perl -e "use SOAP::Lite" SOAP::Lite" "use -e perl perl -e "use SOAP::Lite"rootopen.com
linux命令:perl -e "use SOAP::Lite" SOAP::Lite" "use -e perl perl -e "use SOAP::Lite"rootopen.com
.

引自http://0-9.sakura.ne.jp/blog/archives/2008/10/29121116.html

linux命令:perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')" "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')" -e perl perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')"rootopen.com
linux命令:perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')" "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')" -e perl perl -e "''=~('(?{'.('-^@.]|(;,@/{}/),[\\\$['^'],)@)[\`^@,@[*@[@?}.|').'})')"rootopen.com
.

这个“^ M”是Ctrl-M,它是一个回车符,在Unix文件系统中不需要。其中^ V实际上是Ctrl-V,^ M实际上是Ctrl-M(你必须自己输入,只需复制并粘贴此命令)。 ^ V将不会显示在您的屏幕上。

linux命令:perl -pi -e 's:^V^M::g' <filenames> <filenames> 's:^V^M::g' -e -pi perl perl -pi -e 's:^V^M::g' <filenames>rootopen.com
linux命令:perl -pi -e 's:^V^M::g' <filenames> <filenames> 's:^V^M::g' -e -pi perl perl -pi -e 's:^V^M::g' <filenames>rootopen.com
.

linux命令:perl -pe 's/\d+/++$n/e' file.txt file.txt 's/\d+/++$n/e' -pe perl perl -pe 's/\d+/++$n/e' file.txtrootopen.com
linux命令:perl -pe 's/\d+/++$n/e' file.txt file.txt 's/\d+/++$n/e' -pe perl perl -pe 's/\d+/++$n/e' file.txtrootopen.com
.

在计算大量数字时,在必要时插入逗号。我需要分离大量的数据包,并且在查看终端后12个小时以上,我希望它以可读形式提供。

linux命令:perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse' '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse' -pe perl perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse'rootopen.com
linux命令:perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse' '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse' -pe perl perl -pe '$_=reverse;s/\d{3}(?=\d)(?!.*?\.)/$&,/g;$_=reverse'rootopen.com
.

自我解释见样本输出

linux命令:perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/' s/^([-+]?\d+)(\d{3})/$1.$2/' while -lpe'1 perl perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/'rootopen.com
linux命令:perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/' s/^([-+]?\d+)(\d{3})/$1.$2/' while -lpe'1 perl perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/'rootopen.com
.

MIME :: Base64是Perl5发行版的一部分。你也可以使用decode_base64来得到相反的结果。

linux命令:perl -e 'use MIME::Base64; print encode_base64("encode me plz");' plz");' me encode_base64("encode print MIME::Base64; 'use -e perl perl -e 'use MIME::Base64; print encode_base64("encode me plz");'rootopen.com
linux命令:perl -e 'use MIME::Base64; print encode_base64("encode me plz");' plz");' me encode_base64("encode print MIME::Base64; 'use -e perl perl -e 'use MIME::Base64; print encode_base64("encode me plz");'rootopen.com
.

Linux / dev / full文件模拟“磁盘已满”状况,并且可用于验证程序如何处理这种情况。特别是,几种编程语言实现不会在出现I / O错误时打印错误诊断(也不会退出错误状态) O这样的错误发生,除非程序员已经采取了额外的步骤。也就是说,这些语言中的简单代码不会安全地失败。除了Perl之外,C,C ++,Tcl和Lua(对于某些函数)也不会安全地失败。

linux命令:perl -e 'print 1, 2, 3' > /dev/full /dev/full > 3' 2, 1, 'print -e perl perl -e 'print 1, 2, 3' > /dev/fullrootopen.com
linux命令:perl -e 'print 1, 2, 3' > /dev/full /dev/full > 3' 2, 1, 'print -e perl perl -e 'print 1, 2, 3' > /dev/fullrootopen.com
.

在整个目录及其所有子目录中的每个文件中查找字符串,并用新字符串替换它。更改机器的IP地址或主机名时特别有用 - 在/ etc上运行它。

linux命令:perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*` /<dir>/*` find> to <what -Rl `grep with>/g' it replace to find>/<what to -e's/<what -pi perl perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*`rootopen.com
linux命令:perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*` /<dir>/*` find> to <what -Rl `grep with>/g' it replace to find>/<what to -e's/<what -pi perl perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*`rootopen.com
.

该命令将显示2种模式之间的所有行:word-a和word-buseful用于从文件中清除命令输出

linux命令:perl -0777 -ne 'print "$1\n" while /word-a(.*?)word-b/gs' filename.txt filename.txt /word-a(.*?)word-b/gs' while "$1\n" 'print -ne -0777 perl perl -0777 -ne 'print "$1\n" while /word-a(.*?)word-b/gs' filename.txtrootopen.com
linux命令:perl -0777 -ne 'print "$1\n" while /word-a(.*?)word-b/gs' filename.txt filename.txt /word-a(.*?)word-b/gs' while "$1\n" 'print -ne -0777 perl perl -0777 -ne 'print "$1\n" while /word-a(.*?)word-b/gs' filename.txtrootopen.com
.
共收录0条命令行
这里是记录和分享命令行的地方, 所有命令行都可以进行评论、提交替代方案.

推荐
    热门命令