Linux命令(类似cat)读取指定数量的字符 [英] Linux command (like cat) to read a specified quantity of characters
本文介绍了Linux命令(类似cat)读取指定数量的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在linux中是否有像 cat
这样的命令,可以从文件中返回指定数量的字符?
Is there a command like cat
in linux which can return a specified quantity of characters from a file?
例如,我有一个文本文件如:
e.g., I have a text file like:
Hello world
this is the second line
this is the third line
我想要的东西会返回前5个字符, 。
And I want something that would return the first 5 characters, which would be "hello".
感谢
推荐答案
也可以:
head -c 100 file # returns the first 100 bytes in the file
..将提取前100个字节并返回。
..will extract the first 100 bytes and return them.
使用 head
的好处是, tail
matches:
What's nice about using head
for this is that the syntax for tail
matches:
tail -c 100 file # returns the last 100 bytes in the file
这篇关于Linux命令(类似cat)读取指定数量的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文