我有这个简单的命令:
printf TEST | perl -nle 'print lc'
Run Code Online (Sandbox Code Playgroud)
哪个打印:
test
?
Run Code Online (Sandbox Code Playgroud)
我想要:
test
Run Code Online (Sandbox Code Playgroud)
...没有换行符。我试过 perl 的,printf但它删除了所有的换行符,我想保留现有的。另外,这不适用于我的第二个甚至不使用的示例print:
printf "BOB'S BIG BOY" | perl -ple 's/([^\s.,-]+)/\u\L$1/g'
Run Code Online (Sandbox Code Playgroud)
哪个打印:
Bob's Big Boy
?
Run Code Online (Sandbox Code Playgroud)
...还有那个烦人的换行符。我希望有一个像 --no-newline 这样的神奇开关,但我猜它更复杂。
编辑:我已经改变了我echo在示例中的使用printf来澄清问题。一些评论者正确地指出我的问题实际上并没有像写的那样得到解决。
您只需卸下-l开关,请参阅perldoc perlrun
-l[octnum]
enables automatic line-ending processing. It has two separate
effects. First, it automatically chomps $/ (the input record
separator) when used with -n or -p. Second, it assigns $\ (the output
record separator) to have the value of octnum so that any print
statements will have that separator added back on. If octnum is
omitted, sets $\ to the current value of $/.
Run Code Online (Sandbox Code Playgroud)