Linux command (like cat) to read a specified quantity of characters

前端 未结 9 2063
梦谈多话
梦谈多话 2020-12-12 15:53

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:

Hel         


        
9条回答
  •  鱼传尺愫
    2020-12-12 16:35

    head -Line_number file_name | tail -1 |cut -c Num_of_chars
    

    this script gives the exact number of characters from the specific line and location, e.g.:

    head -5 tst.txt | tail -1 |cut -c 5-8
    

    gives the chars in line 5 and chars 5 to 8 of line 5,

    Note: tail -1 is used to select the last line displayed by the head.

提交回复
热议问题