我需要在我的Bash脚本中编写函数来“加密”文本。 我决定使用AWK来实现这个功能,但我遇到了一个问题。
不幸的是我不知道如何在字符串中找到字符的位置:
示例字符串:
abcdefghijklmnopqrstuvwxyz=,;.:-_+*?()!$&<>|ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
结果:
input a -> output 1
input b -> output 2
...
input = -> output 27
...
input 8 -> output 79
input 9 -> output 80
...
输入始终只有一个字符。
你有什么想法我怎么能做这样的事情(最好是在AWK)?
谢谢, 格雷戈里
答案 0 :(得分:2)
您可以使用index
函数查找字符串中子字符串的索引。
用法
index(string, substring)
例如
$ awk '{print index("hello world", "h") }'
1
$ awk '{print index("hello world", "e") }'
2