perl :^I;regexp;push/pop/正则集合
发布时间:2020-12-15 23:49:43 所属栏目:大数据 来源:网络整理
导读:this function is for add 3 space for each line between { } 1? #!/opt/exp/bin/perl -w $^I=".bak";while () {if (/{/) {print $_;push @symbol,'}';}if (/}/) {print $_;pop @symbol;}if (!/{/ !/}/) {$number =@symbol;if ($number0) {print " $_";} el
this function is for add 3 space for each line between { } 1?#!/opt/exp/bin/perl -w $^I=".bak"; while (<>) { if (/{/) { print $_; push @symbol,'}'; } if (/}/) { print $_; pop @symbol; } if (!/{/ && !/}/) { $number =@symbol; if ($number>0) { print " $_"; } else { print $_; } } } 2? $string =~ s/<.*?>//g; $string =~ s/<.*>//g; 不行 perl -pe 's/<.*>//g' ucfirst.pl are also fine第一个是非最贪心匹配!!! 对于这样的文本例子 abc<abccde>ddef>x 第一个将其转成 abcddef>x 第二个是 abcx or,多选匹配 # 不管是“scarlet”“ruby”还是“puce”,一律换成“red perl -pe 's/scarlet|ruby|puce/red/g' 8.txt否定匹配 $temp=""; while (<>) { if (!/^$/) { print $temp; } $temp=$_; } 区间范围的匹配 # 显示两个正则表达式之间的文本(包含) perl -ne 'print if /Iowa/../Montana/' 正则掠过空白行和#comment行 在指定范围行前加comments perl -pe 's/^/#/ if ($. >16 && $.<28)' 3-13.pl skip 空行和comments行 perl -ne 'print $_ unless (/^$/ ||/^#/);' filename # 显示包含65个以下字符的行 perl -nle 'print unless /.{65}/' # 删除文件中的所有空行(与“grep ‘.’ ”效果相同) perl -ne 'print if /./' perl -pe 's/n/ / if $.%2'正则错误部分 正则替换部分,不能有正则 $string =~ /-?(/d+)/.?(/d+)/; $string =~ s/-?(d+)/.$1/; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |