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

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 release
PATH=/bin:$PATH
export PATH

users=$(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 options

Without too much talk let‘s start by introducing main and the most commonly used cut command line options.

-b, --bytes=LIST
Cuts the input file using list of bytes specified by this option
-c, --characters=LIST
Cuts the input file using list of characters specified by this option
-f, --fields=LIST
Cuts 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=DELIMITER
Specifies a delimiter to by used as a field. As mentioned previously default field is TAB and this option overwrites this default behavior.
Using LIST

List 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 1
2-5 will display all bytes, characters or fields starting from second and finishing by 5th
-3 will display all bytes, characters or fields before 4th
5- will produce all bytes, characters or fields starting with 5th
1,3,6 will display only 1st, 3rd and 6th byte, character or field
1,3- displays 1st and all bytes, characters or fields starting with 3th
Let‘s see how this works in practice.

Cut by Character

In 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.txt
cut
$ cut -c 2-5 cut.txt
ut-c
$ cut -c 5- cut.txt
command
Cut By Byte

The 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.txt
u
$ cut -b -3 cut.txt
cut
$ cut -b 2-5 cut.txt
ut-c
$ cut -b 5- cut.txt
command

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

时间: 2024-10-28 11:20:57

linux cut: invalid byte, character or field list Try 'cut --help' for more information.的相关文章

pentaho中Invalid byte 3 of 3-byte UTF-8 sequence的解决方法

今天在创建数据源的时候报了这么一个错 Invalid byte 3 of 3-byte UTF-8 sequence. 上网一查,说是有中文,字体不相符,可是我没有写中文,为了能继续往后进行,修改了如下文件 在start-pentaho.bat中添加了一句代码 修改前 IF "%BITS%" == "64" ( set CATALINA_OPTS=-Xms1024m -Xmx2048m -XX:MaxPermSize=256m -Dsun.rmi.dgc.clien

Invalid byte 3 of 3-byte UTF-8 sequence

用maven编译,tomcat启动时报错:IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence,能确定是编码问题.

tomcat部署新的项目的时候出现报错信息: Invalid byte tag in constant pool: 15

上面一堆tomcat启动的提示信息省略掉,下面是报错的具体信息:org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15 at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131) at org.apache.tomcat.util.bcel.classfi

ruby环境sass编译中文出现Syntax error: Invalid GBK character错误解决方法

sass文件编译时候使用ruby环境,无论是界面化的koala工具还是命令行模式的都无法通过,真是令人烦恼. 容易出现中文注释时候无法编译通过,或者出现乱码,找了几天的解决方法终于解决了. 这个问题的奇葩之处在于在xp环境中没有任何问题,只是在windows7环境中才出现的这个. sass编译时候出现如下错误的解决方法: Syntax error: Invalid GBK character "\xE5" on line 8 of E:\work\sass\sass\_big_box.

warning: #870-D: invalid multibyte character sequence

warning: #870-D: invalid multibyte character sequence2011-03-12 9:18warning: #870-D: invalid multibyte character sequenceconst unsigned char mm[]={"中华人民共和国"};MDK3.40版本版本有告警,C-MDK 3.70正常警告内容告诉你:invalid multibyte character sequence 非法的多字节字符串. 这就是说

tomcat部署新的项目启动时出现报错信息: Invalid byte tag in constant pool: 15

...... org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15 at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131) at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(C

错误解决 :Invalid byte 3 of 3-byte UTF-8 sequence.

最近使用ant 多渠道打包  老是编译不成功 提示如下错误 I/O error for /wemicommunity/AndroidManifest.xml: Invalid byte 3 of 3-byte UTF-8 sequence. 网上查了很多资料后 认定是字符编码问题 应该是在其它编码格式文件    直接粘贴到UTF-8 编码格式的项目里 导致了乱码 具体解决办法是 1   使用记事本打开 2    另存为   使用UFT-8 保存 3  打开文件 将错误的编码删除 字符编码问题迎刃

编译sass,遇到报错error style.scss (Line 3: Invalid GBK character &quot;\xE5&quot;)

今天学习sass,写了一行中文注释,结果却遇到了报错: 1 cmd.exe /D /C call C:/Ruby23-x64/bin/scss.bat --no-cache --update style.scss:style.css 2 error style.scss (Line 3: Invalid GBK character "\xE5") 3 4 Process finished with exit code 1 以前在公司使用的mac没用遇到这种问题,当使用windows 7

使用maven构建 ssm项目 tomcat7插件运行报错, Invalid byte tag in constant pool: 60

错误日志: [WARNING] [WARNING] Some problems were encountered while building the effective settings[WARNING] Unrecognised tag: 'profile' (position: START_TAG seen ...</activation> -->\n\t\t<profile>... @264:12) @ D:\DevSoftInstall\apache-maven-3