bash 获取文件中字符串
How to get the one character’s next character in ASCII table in Bash? For example, if I have ‘a’ in variable i
, how to get ‘b’?
如何在Bash的ASCII表中获取一个字符的下一个字符? 例如,如果我在变量i
有“ a”,如何获得“ b”?
First, we need to get the integer value for the character.
首先,我们需要获取字符的整数值。
char='b'
charint=$(printf "%d" "'$char'")
Then, we increase the integer by one
然后,我们将整数增加一
let charint=$charint+1
Last, we can get the new character by converting the integer to the character
最后,我们可以通过将整数转换为字符来获得新字符
newchar=$(printf "\x$(printf %x $charint)")
Here, we use the inner printf
to convert the integer to hexadecimal value and the outer printf
to print the character from its hexadecimal value.
在这里,我们使用内部printf
将整数转换为十六进制值,并使用外部printf
从字符的十六进制值打印字符。
The result is as follows.
结果如下。
$ echo $newchar
c
翻译自: https://www.systutorials.com/how-to-get-the-one-characters-next-character-in-ascii-table-in-bash/
bash 获取文件中字符串