linux cut: invalid byte, character or field list Try 'cut --help' for more information.

來源:互聯網
上載者:User

標籤:most   produce   therefore   執行   命令   character   first   sel   port   

1. 概述

centos執行簡單shell 指令碼 報錯

cut: invalid byte, character or field list
Try ‘cut --help‘ for more information.

2. 代碼

  vim userid.sh

#!/bin/bash#Program#       Use id, finger command to check system account‘s information.#History#2015/07/17 logan first releasePATH=/bin:$PATHexport PATHusers=$(cut -d ‘:‘ -fl /etc/passwd)#注意這行!!!!!!!!!!!!!for username in ${users}do        id ${username}done

3. 解決問題

   代碼中cut命令 後跟的選項及參數有誤 應該是數字1而不是字母l

4. cut 命令學習請參考 https://linuxconfig.org/learning-linux-commands-cut

以下為節選

Frequently used optionsWithout too much talk let‘s start by introducing main and the most commonly used cut command line options.-b, --bytes=LISTCuts the input file using list of bytes specified by this option-c, --characters=LISTCuts the input file using list of characters specified by this option-f, --fields=LISTCuts the input file using list of field. The default field to be used TAB. The default behavior can be overwritten by use of -d option.-d, --delimiter=DELIMITERSpecifies a delimiter to by used as a field. As mentioned previously default field is TAB and this option overwrites this default behavior.Using LISTList in this case can consist of single or range of bytes, characters or fields. For example to display only second byte the list will include a single number 2 .Therefore:2 will display only second byte, character or field counted from 12-5 will display all bytes, characters or fields starting from second and finishing by 5th-3 will display all bytes, characters or fields before 4th5- will produce all bytes, characters or fields starting with 5th1,3,6 will display only 1st, 3rd and 6th byte, character or field1,3- displays 1st and all bytes, characters or fields starting with 3thLet‘s see how this works in practice.Cut by CharacterIn the following examples are rather self-explanatory. We used cut‘s -c option to print only specific range of characters from cut.txt file.echo cut-command > cut.txt $ cut -c 2 cut.txt u$ cut -c -3 cut.txtcut$ cut -c 2-5 cut.txtut-c$ cut -c 5- cut.txtcommandCut By ByteThe principle behind -b ( by byte ) option is similar to the one described previously. We know that a single character has size of 1 byte and therefore result after executing previous commands with -b option will be exactly the same:$ cut -b 2 cut.txtu$ cut -b -3 cut.txtcut$ cut -b 2-5 cut.txtut-c$ cut -b 5- cut.txtcommand

 

linux cut: invalid byte, character or field list Try 'cut --help' for more information.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.