本文介绍了从使用文本文件的bash读取字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道我可以从文件中读取前两个字符,使用bash脚本。有问题的文件实际上是一个I / O驱动程序,它在它没有新行字符,而实际上是无限长。
Does anyone know how I can read the first two characters from a file, using a bash script. The file in question is actually an I/O driver, it has no new line characters in it, and is in effect infinitely long.
推荐答案
的读
内置支持 -n
参数:
$ echo "Two chars" | while read -n 2 i; do echo $i; done
Tw
o
ch
ar
s
$ cat /proc/your_driver | (read -n 2 i; echo $i;)
这篇关于从使用文本文件的bash读取字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!