tr“[za]” '[az]'产生错误消息
我想用 tr
命令模拟 rev
命令(在字母表上)
所以我这样做了这
echo abcdefghijklmnopqrstuvxyz | tr '[z-a]' '[a-z]'
给了我
tr:“za”的范围端点采用反向整理序列顺序
所以我尝试了
echo abcdefghijklmnopqrstuvxyz | tr 'abcdefghijklmnopqrstuvxyz' 'zyxvutsrqponmlkjihgfedcba'
,它工作正常,输出是zyxvutsrqponmlkjihgfedcba
tr'[za]''[az]是错误的'
?
如果我指定 tr '[ac]' '[ca]'
它也可以正常工作。
任何帮助将不胜感激
谢谢
I want to emulate rev
command (on alphabet) with the tr
command
So I did this
echo abcdefghijklmnopqrstuvxyz | tr '[z-a]' '[a-z]'
That gives me
tr: range-endpoints of `z-a' are in reverse collating sequence order
So I tried
echo abcdefghijklmnopqrstuvxyz | tr 'abcdefghijklmnopqrstuvxyz' 'zyxvutsrqponmlkjihgfedcba'
and it works ok, output is zyxvutsrqponmlkjihgfedcba
That is wrong with tr '[z-a]' '[a-z]'
?
If I specify tr '[a-c]' '[c-a]'
it also works fine.
Any help would be appreciated
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你对“[ca]”很幸运,我的 tr 说
tr:[ca]:无效的目标字符串
,这正是我所期望的。在我处理过的所有语言中,字符范围(即 [az])的值都需要上升。
很高兴您已经找到了解决方案。
或者编写一个可以使用的函数,例如
tr "[az]" "[$( revCharRange az )]"
(由于创建反向字符范围所需的子外壳,这会更昂贵。
编辑
其中
revCharRange az
将输出zyxw...cba
我希望这会有所帮助。
I think your lucky with the '[c-a]' thing, My tr says
tr: [c-a]: invalid destination string
, which is what I would expect.Character ranges, i.e. [a-z], in all the languages I've dealt with, need to ascend in value.
Be happy that you've already figured out your solution.
Or write a function that you can use like
tr "[a-z]" "[$( revCharRange a-z )]"
(which would be more expensive due to the sub-shells required to create the reverse character range.
Edit
where
revCharRange a-z
would outputzyxw...cba
I hope this helps.