Linux中是否有类似cat
的命令可以从文件中返回指定数量的字符?
例如,我有一个文本文件,例如:
Hello world
this is the second line
this is the third line
我想要的东西可以返回前5个字符,即“hello”。
谢谢
最佳答案
head
也可以工作:
head -c 100 file # returns the first 100 bytes in the file
..将提取前100个字节并将其返回。
为此使用
head
的好处是tail
的语法匹配:tail -c 100 file # returns the last 100 bytes in the file
您可以将它们组合以获得字节范围。例如,要从文件中获取后100个字节,请使用
head
读取前200个字节,并使用tail获取后100个字节:head -c 200 file | tail -c 100
关于linux - Linux命令(如cat)读取指定数量的字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/218912/