Perlスクリプトは、LinuxのbashシェルとHP unixの/sbin/shシェルで異なる出力を提供します。

Perlスクリプトは、LinuxのbashシェルとHP unixの/sbin/shシェルで異なる出力を提供します。

入力する:

tmp# cat test5
1234      012345
0.000             01234
01/02/03          5467
01234           0123
05554567       234
0099
0000           000054

Bashシェルからの出力:

[tmp]# perl -lpe 's#(^|\h)\K0[^./\h]+(?=\h|$)#"$&"#g' test5
1234      "012345"
0.000             "01234"
01/02/03          5467
"01234"           "0123"
"05554567"       234
"0099"
"0000"           "000054"

/sbin/shHP Unixのシェル出力:

/tmp # perl -lpe 's#(^|\h)\K0[^./\h]+(?=\h|$)#"$&"#g' test5
1234      012345
0.000             01234
01/02/03          5467
01234           0123
05554567       234
0099
0000           000054

ベストアンサー1

欲しいと思う手紙を書く0 で始まるすべての整数値を引用します。この目標を達成する簡単なREは次のとおりです。

perl -lpe '1 while (s/(^|\s)(0\d*)(\s|$)/$1"$2"$3/)' test5

1234      "012345"
0.000             "01234"
01/02/03          5467
"01234"           "0123"
"05554567"       234
"0099"
"0000"           "000054"

おすすめ記事