while (<>) { script }
while (<>) { script } continue { print; }
echo "key name1 value2 value3" | perl -ne 's/[ ]{2,}/\t/g;print;' | cut -f 2 value2
cat /path/to/example.log | perl -ne 'BEGIN{$max=0;$line} $len=length; if($len > $max){$max=$len;$line=$_;} END{print "$max," . substr($line,0,512) . "\n";}'
echo "SELECT name, password FROM user WHERE id='abc12823' and password='k#eyAW37';" | perl -ne 'BEGIN {$sq="\x27";} print "$1\n" if /(id\s*=\s*$sq[^$sq]*$sq)/g' id='abc12823'
perlrun - Perl インタプリタの起動方法 - perldoc.jp
echo "http://perldoc.jp/docs/modules/URI-1.35/URI/Split.pod" | perl -MURI::Split=uri_split -wne 'my($scheme, $auth, $path, $query, $frag)=uri_split($_);print $auth' perldoc.jp
echo "http://perldoc.jp/docs/modules/URI-1.35/URI/Split.pod" | perl -MURI -wne 'print URI->new($_)->host' perldoc.jp
curl -s -I https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js | perl -ane "if(/Last-Modified: /){print $';}" | xargs -i date '+%Y-%m-%d %H:%M:%S %Z' -d {} 2016-07-12 16:12:44 JST
echo -e "test\n3600.00 secs (1.00 hrs)" | perl -0ne 'if(/test.*?(\d+\.\d+)\s*hrs/s){print "$1";}' 1.00
echo -e "123\n456\n789" | perl -0pe 's/3.+?45//s' 126 789
perl -ne 'if(m#01/Aug/2013:(\d+)#){$c{$1}++}END{for(keys %c){print "$_ $c{$_}\n"} }' /var/log/httpd/access_log | sort -n # 結果 時 件数 01 113 02 243
perl -ne 'if(m#01/Aug/2013:(\d+:\d+)#){$c{$1}++}END{for(keys %c){print "$_ $c{$_}\n"} }' /var/log/httpd/access_log | sort -n # 結果 時:分 件数 01:58 5 01:59 3 02:00 5
vim /tmp/test.log ---- 1 2 3 4 5 ---- cat /tmp/test.log | perl -ne 'BEGIN{$sum=0;} if($. <= 2){$sum+=$_;} END{print $sum;}' 3
perl -e '$m=readpipe("free -m");$m=~/Swap:\s+(\d+)/i;print int($1)'
perl -e '$m=readpipe("free -m");$m=~/Mem:\s+(\d+)/i;print int($1)'
perl -e '$m=readpipe("free -m");$m=~/cache:\s+(\d+)\s+(\d+)/i;print int($2)'
cat example.log | perl -ane 'if(/ (\d+\.\d+) /) { if($1 >= 2) { print "$1\n";} }' | wc -l
perl -p -i -e "s/\r\n/\n/g" *.sh
perl -p -i -e "s/^\t+//g" *.txt
# ansible.cfgの「#control_path」「control_path」を削除 ag control_path -G ansible.cfg -l | xargs -i perl -p -i -e "s/^[\#]*control_path.+[\r\n]+//g" {} # ansible.cfgの「control_path」を追加 ag -g ansible.cfg -l | xargs -i perl -p -i -e "s#^\[ssh_connection\][\r\n]+#$&control_path = %(directory)s/%%C\n#g" {}
bash --version | perl -ane 'if($.==1 && /version (\d+)\./){ print $1;}' # 3
perl -ane '/CentOS release ([5-6])|Red Hat Enterprise Linux .* ([5-6])/; print $1' /etc/redhat-release # 6
httpd -v | perl -ane 'if( $F[2]=~/Apache\/(\d+\.\d+)/ ){ print $1; }' # 2.2
df -P -m /mnt 2>&1 | perl -ane 'if($.==2) {print $F[1];}'
df -P -m /mnt 2>&1 | perl -ane 'if($.==2) {print $F[2];}'
df -P -m /mnt 2>&1 | perl -ane 'if($.==2) {print $F[3];}'
perl -F, -ane 'if($F[0] eq "a" && $F[1] eq "b") { $F[0]=~s/\x0D?\x0A?$//;print $F[0]; }' sample.csv
#ファイルを行単位でソートします perl -e 'print sort <>' file #ファイルをパラグラフ単位でソートします perl -00 -e 'print sort <>' file #複数ファイルをファイル毎比較してソートしてから1本のファイルとして表示し ます perl -0777 -e 'print sort <>' file1 file2