使用bash从文本文件中读取字符

Sim*_*son 4 linux bash file-io

有谁知道如何使用bash脚本从文件中读取前两个字符.有问题的文件实际上是一个I/O驱动程序,它没有新的行字符,并且实际上是无限长的.

Vin*_*vic 11

read内置支持-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;)
Run Code Online (Sandbox Code Playgroud)