Perl 中管道字符的分割
我有一个小问题。我想在使用分割运算符找到的每个管道字符处分割一行。就像这个例子一样。
echo "000001d17757274585d28f3e405e75ed
I have a little problem. I want to split a line at every pipe character found using the split operator. Like in this example.
echo "000001d17757274585d28f3e405e75ed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
|1
|1
||||" | \
perl -ane '$data = $_ ; chop $data ; @d = split(/\|/ , $data) ; print $#d+1,"\n" ;'
我预计输出为 36
因为
awk
使用分隔符|
分割返回 36,但我得到 12,就好像分割停在行中的1
字符处一样。||||" | \
perl -ane '$data = $_ ; chop $data ; @d = split(/\|/ , $data) ; print $#d+1,"\n" ;'
I would expect an ouput of 36
as
awk
splitting with the delimiter|
return 36, but instead I get 12, as if the split stopped at the1
character in the line.|1
|1
|||||||||" | \
awk -F"|" '{print NF}'
任何想法。我尝试了多种引用
|
的方法,但没有成功。非常感谢。
|||||||||" | \
awk -F"|" '{print NF}'
Any idea. I have tried many ways of quoting the
|
, but without success.Many thanks by advance.
根据
split
:您需要为分割指定负限制才能获取尾随的分割:
According to
split
:You need to specify a negative limit to the split to get the trailing ones: