当前位置: 首页 > news >正文

linux 操作系统下的cut命令介绍和使用案例

linux 操作系统下的cut命令介绍和使用案例

在 Linux 操作系统中,cut 命令是一个用于文本处理的命令行工具,允许用户从文件或管道数据中提取特定部分并将结果输出到标准输出

1. cut 命令简介

cut 命令主要用于从文本文件中提取特定的字段、字节或字符。它常用于处理结构化数据文件,如 CSV 或 TSV 文件,能够根据分隔符(如逗号或制表符)提取列。

基本语法

bash
cut [OPTIONS] [FILE]
  • OPTIONS: 用于指定如何切割文本的选项。
  • FILE: 要处理的文件名。如果未指定文件名,cut 将从标准输入读取数据。

2. cut 命令选项

选项

描述

-f 或 --fields=LIST

根据指定字段(列)选择数据。

-b 或 --bytes=LIST

根据指定字节选择数据。

-c 或 --characters=LIST

根据指定字符选择数据。

-d 或 --delimiter

指定分隔符,默认为制表符(TAB)。

-s 或 --only-delimited

只输出包含分隔符的行。

--complement

显示所有字节、字符或字段,除了选定的部分。

--output-delimiter

指定输出的分隔符,默认为输入的分隔符。

命令介绍:

root@meng:~# which cut

/usr/bin/cut

root@meng:~# cut --help

Usage: cut OPTION... [FILE]...

Print selected parts of lines from each FILE to standard output.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.

-b, --bytes=LIST select only these bytes

-c, --characters=LIST select only these characters

-d, --delimiter=DELIM use DELIM instead of TAB for field delimiter

-f, --fields=LIST select only these fields; also print any line

that contains no delimiter character, unless

the -s option is specified

-n (ignored)

--complement complement the set of selected bytes, characters

or fields

-s, --only-delimited do not print lines not containing delimiters

--output-delimiter=STRING use STRING as the output delimiter

the default is to use the input delimiter

-z, --zero-terminated line delimiter is NUL, not newline

--help display this help and exit

--version output version information and exit

Use one, and only one of -b, -c or -f. Each LIST is made up of one

range, or many ranges separated by commas. Selected input is written

in the same order that it is read, and is written exactly once.

Each range is one of:

N N'th byte, character or field, counted from 1

N- from N'th byte, character or field, to end of line

N-M from N'th to M'th (included) byte, character or field

-M from first to M'th (included) byte, character or field

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>

Report any translation bugs to <https://translationproject.org/team/>

Full documentation <https://www.gnu.org/software/coreutils/cut>

or available locally via: info '(coreutils) cut invocation'

root@meng:~# cut

cut: you must specify a list of bytes, characters, or fields

Try 'cut --help' for more information.

root@meng:~#

命令案例:

root@meng:~# more s2.txt

his is a test

HloWorld

Hlo World

Hlo World

g

g

hlo men

hlo meng

root@meng:~# cut -b 1-3 s2.txt

Hlo

Hlo

Hlo

g

g

hlo

hlo

root@meng:~# cut -d ' ' -f 2 s2.txt

is

is World

World

World

g

g

men

meng

root@meng:~#

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • JVM字节码
  • UVA1395 Slim Span(最小生成树)
  • Unity3d 以鼠标位置点为中心缩放视角(正交模式下)
  • 详解c++多态---上
  • 动态规划---不相交的线
  • 【前端】ref引用的作用
  • Golang、Python、C语言、Java的圆桌会议
  • Vue.js 计算属性
  • 数据结构:堆的算法
  • Nginx 文件名逻辑漏洞(CVE-2013-4547)
  • ESP8266做httpServer提示Header fields are too long for server to interpret
  • 【论文分享精炼版】 sNPU: Trusted Execution Environments on Integrated NPUs
  • NAT技术
  • vue3 +百度地图 实现 地点检索,输入联想,经纬度,逆地理编码,创建标记,label等
  • LAMP+WordPress
  • bearychat的java client
  • Docker 笔记(1):介绍、镜像、容器及其基本操作
  • JAVA之继承和多态
  • leetcode讲解--894. All Possible Full Binary Trees
  • MD5加密原理解析及OC版原理实现
  • Median of Two Sorted Arrays
  • mongodb--安装和初步使用教程
  • Redux 中间件分析
  • SpringBoot几种定时任务的实现方式
  • Vue2.0 实现互斥
  • WordPress 获取当前文章下的所有附件/获取指定ID文章的附件(图片、文件、视频)...
  • 从输入URL到页面加载发生了什么
  • 机器学习 vs. 深度学习
  • 力扣(LeetCode)56
  • 算法-图和图算法
  • 吐槽Javascript系列二:数组中的splice和slice方法
  • 微信如何实现自动跳转到用其他浏览器打开指定页面下载APP
  • 写代码的正确姿势
  • 大数据全解:定义、价值及挑战
  • 正则表达式-基础知识Review
  • ​​快速排序(四)——挖坑法,前后指针法与非递归
  • ​DB-Engines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
  • ‌JavaScript 数据类型转换
  • # 服务治理中间件详解:Spring Cloud与Dubbo
  • #git 撤消对文件的更改
  • #QT(TCP网络编程-服务端)
  • (09)Hive——CTE 公共表达式
  • (1)bark-ml
  • (2/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (2009.11版)《网络管理员考试 考前冲刺预测卷及考点解析》复习重点
  • (备忘)Java Map 遍历
  • (第61天)多租户架构(CDB/PDB)
  • (十)【Jmeter】线程(Threads(Users))之jp@gc - Stepping Thread Group (deprecated)
  • (四) 虚拟摄像头vivi体验
  • (四)JPA - JQPL 实现增删改查
  • (新)网络工程师考点串讲与真题详解
  • (一)插入排序
  • (一)为什么要选择C++
  • .bat文件调用java类的main方法
  • .NET Core中Emit的使用