当前位置:网站首页>Example of using the cut command
Example of using the cut command
2022-08-09 06:33:00 【qq_36412526】
cut command is used for text processing.You can use this command to extract a portion of text from a file by selecting a column
Options for the cut command
Cut basic syntax:
cut OPTION... [FILE]...Options:
-f : By specifying which field to extract.The cut command uses "TAB" as the default field separator.
-d : "TAB" is the default delimiter, use this option to change to other delimiters.
--complement : This option is used to exclude the specified field.
--output-delimiter : Change the delimiter for output content.
How to split
The most common options for cut are the combination of -d and -f.It basically extracts content based on a specific delimiter and the fields listed.
The following code uses only delimiters: prints the first field of each line in the /etc/passwd file.
[email protected]:~# cut -d ':' -f 1 /etc/passwdrootdaemonbinsyssyncgamesmanlpmailnewsuucpproxywww-databackuplistircgnatsThe following code extracts the first and sixth fields from the /etc/passwd file:
[email protected]:~# grep '/bin/bash' /etc/passwd| cut -d ':' -f 1,6root:/rootforlinx:/home/forlinxybtxr:/home/ybtxrTo display the range of fields, specify the start and end fields separated by - as follows:
[email protected]:~# grep '/bin/bash' /etc/passwd|cut -d ':' -f 1-4,6,7root:x:0:0:/root:/bin/bashforlinx:x:1000:1000:/home/forlinx:/bin/bashybtxr:x:1001:1001:/home/ybtxr:/bin/bashExclude specified fields
In the code below, print all fields except the second field in the /etc/passwd file:
[email protected]:~# grep '/bin/bash' /etc/passwd|cut -d ':' --complement-f 2root:0:0:root:/root:/bin/bashforlinx:1000:1000:A40i,,,:/home/forlinx:/bin/bashybtxr:1001:1001:,,,:/home/ybtxr:/bin/bashHow to specify a delimiter for output content
To specify the output delimiter, use the --output-delimiter option.The input delimiter is specified by the -d option, by default the output delimiter is the same as the input delimiter.
Let's take a look at what it looks like without the --output-delimiter option:
[email protected]:~# cut -d ':' -f1,7 /etc/passwd|sortavahi-autoipd:/bin/falseavahi:/bin/falsebackup:/bin/shbin:/bin/shcolord:/bin/falseNow use the --output-delimiter option, the output delimiter is separated by ' ' space, and see what it looks like:
[email protected]:~# cut -d ':' -f1,7 --output-delimiter=' ' /etc/passwd|sortavahi-autoipd /bin/falseavahi /bin/falsebackup /bin/shbin /bin/shSummary
A limitation of thecut command is that it does not support specifying multiple characters as delimiters.Multiple spaces are treated as multiple field separators and the tr command must be used to get the desired output.
边栏推荐
- Flask failed to create database without error
- 线程池总结
- 常用Oracle命令
- Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
- install flask
- 简单工厂模式
- pdf加密、找回密码
- The solution that does not work and does not take effect after VScode installs ESlint
- Simple Factory Pattern
- 简单使用Lambda表达式
猜你喜欢

Excel受保护的工作表怎么操作?

安装flask

报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道

Likou Brush Question 180

PDF不能打印和复制的问题如何解决?

Flask failed to create database without error

db.sqlite3没有“as Data Source“解决方法

Output method of list string print(*a) print(““.join(str(c) for c in a) )

CMake中INSTALL_RPATH与BUILD_RPATH问题

中英文说明书丨CalBioreagents ACTH N端单克隆抗体
随机推荐
Unity C# 委托——事件,Action,Func的作用和区别
DevNet: Deviation Aware Networkfor Lane Detection
Program Performance Analysis - Complexity Analysis
IQ Products巨细胞病毒CMV感染检测试剂盒的特征和应用
Redis 2 - 高级
输入框最前面添加放大镜&&background-image和background-color冲突问题
e-learning summary
C语言的内置宏(定义日志宏)
无重复的字符的最长子串
Reverse Engineering
ByteDance Interview Questions: Mirror Binary Tree 2020
Quectel EC20 4G module dial related
Common Oracle Commands
db.sqlite3 has no "as Data Source" workaround
简单工厂模式
详解C语言中的wait()函数和waitpid()函数
[HNOI2002]营业额统计
ZIP压缩包文件删除密码的方法
单例模式
我入职阿里后,才知道原来简历这么写