官术网_书友最值得收藏!

The cut command

The cut command is used to extract specified columns/characters of a piece of text, which is given as follows:

  • -c: Specifies the filtering of characters
  • -d: Specifies the delimiter for fields
  • -f: Specifies the field number

The following are a few examples that show the usage of the cut command:

  • Using the next command, from the /etc/passwd file, fields 1 and 3 will be displayed. The display will contain the login name and user ID. We use the -d: option to specify that the field or columns are separated by a colon (:):
   $ cut -d: -f1,3 /etc/passwd

  • Using this command, from the /etc/passwd file, the fields 1 to 5 will be displayed. The display will contain the login name, encrypted password, user ID, group ID, and user name:
    $ cut -d: -f1-5 /etc/passwd

  • This command will show characters 1 to 3 and 8 to 12 from the emp.lst file:
    $ cut -c1-3,8-12 /home/student/emp.lst
  • The output of the date command is sent as an input to the cut command and only the first three characters are printed on screen, which is shown as follows:
    $ date | cut -c1-3
    Mon
主站蜘蛛池模板: 朝阳县| 浦城县| 桂平市| 襄城县| 金坛市| 毕节市| 乌鲁木齐市| 滨州市| 堆龙德庆县| 合阳县| 新密市| 青铜峡市| 中江县| 隆尧县| 石狮市| 安丘市| 忻城县| 阜康市| 平和县| 资溪县| 鄢陵县| 元阳县| 安国市| 盖州市| 松江区| 邵阳市| 武隆县| 彭山县| 五家渠市| 全椒县| 咸阳市| 马龙县| 交城县| 灵丘县| 福海县| 合川市| 温州市| 松原市| 牡丹江市| 乌拉特后旗| 霍城县|