Bash 如何将一个字符更改为另一个字符?

Bash 如何将一个字符更改为另一个字符?,bash,Bash,我要更改此字符串: At, U omz rqqx uf itqz kag'dq zqmd yq Oh, I can feel it when you're near me 插入此字符串: At, U omz rqqx uf itqz kag'dq zqmd yq Oh, I can feel it when you're near me 这意味着a(ASCII=97)变成o(ASCII=111),依此类推 如何在bash脚本中更改此字符串?您可以使用tr命令进行此类翻译tr接受描述从和到

我要更改此字符串:

At, U omz rqqx uf itqz kag'dq zqmd yq
Oh, I can feel it when you're near me
插入此字符串:

At, U omz rqqx uf itqz kag'dq zqmd yq
Oh, I can feel it when you're near me
这意味着
a(ASCII=97)
变成
o(ASCII=111)
,依此类推


如何在bash脚本中更改此字符串?

您可以使用
tr
命令进行此类翻译
tr
接受描述
字符的字符串。在本例中,它可能类似于以下内容(我没有编写整个序列-这只是一个示例):


该字符串使用rot14 chiffre加密。您可以使用以下
tr
命令对其进行解密:

tr '[A-Za-z]' '[O-ZA-No-za-n]' <<< "At, U omz rqqx uf itqz kag'dq zqmd yq"
说明:


输入字符集包括大小写ascii字符
[A-Za-z]
。你说chiffre
a
翻译成
o
。假设字符串是用rot14加密的,同样的情况也适用于
A
O
。这就是为什么输出字符集从
O
开始。到达
Z
后,我们继续执行
A
,直到
N
(位于
O
之前)。这是向前旋转14圈。这同样适用于小写字符。

它生成的输出为
哦,我在
tr(GNU coreutils)8.4
上cmz rqqx uf ihqz kag'dq zqmd yq
,我在这里遗漏了什么吗?@Inian是的,你遗漏了我对不完整列表的评论。没有重新收集我的坏消息!顺便说一句,我没有投你反对票。@GMichael你没有解决问题。这就是为什么down-vote.google
ROT
ROT13
,并在linuxWorks中使用
tr
实现的原因<代码>+1你能解释一下
[…a-z]
如何对应于
[…a-No-za-n]
,我在那里不知所措。@Inian的格式是a->O,B->P,…,z->n。也就是说,
tr
将一个列表中的每个元素映射到另一个列表中对应的元素。