当前位置:网站首页>知道这几个命令让你掌握Shell自带工具
知道这几个命令让你掌握Shell自带工具
2022-06-28 15:46:00 【51CTO】

前篇文章由案例驱动,总结了Sell中的基本语法,这篇文章带大家由案例驱动学习下Sell中的自带的工具命令。
Cut
cut的工作就是“剪”,具体的说就是在文件中负责剪切数据用的。cut 命令从文件的每一行剪切字节、字符和字段并将这些字节、字符和字段输出。
基本用法
参数说明
- -f :列号,提取第几列
- -d :分隔符,按照指定分隔符分割列
案例:
首先进入到linux系统中,准备数据

案例1:切割cat.txt第一列

案例2:切割cat.txt第二、三列

案例3:在cat.txt文件中切割出lisi

Sed
sed是一种流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”,接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非你使用重定向存储输出。
基本用法
参数说明
- -e : 直接在指令列模式上进行sed的动作编辑
命令功能
- a : 新增,a的后面可以接字串,在下一行出现
- d : 删除
- s :查找并替换
案例:
准备数据

案例1:将“hello wawa”这个词插入到sed.txt第二行下,打印

ps:文件并没有改变
案例2:删除sed.txt文件所有包含wo的行

案例3:将sed.txt文件中wo替换为ni

Awk
一个强大的文本分析工具,把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行分析处理。
基本用法
参数说明
- -F : 指定输入文件折分隔符
- -v : 赋值一个用户定义变量
案例:
准备数据
搜索passwd文件以root关键字开头的所有行,并输出该行的第7列。

awk的内置变量
- FILENAME 文件名
- NR 已读的记录数
- NF 浏览记录的域的个数(切割后,列的个数)
案例:
统计passwd文件名,每行的行号,每行的列数

Sort
sort命令是在Linux里非常有用,它将文件进行排序,并将排序结果标准输出。
基本语法
参数说明
- -n 依照数值的大小排序
- -r 以相反的顺序来排序
- -t 设置排序时所用的分隔字符
- -k 指定需要排序的列
案例:
准备数据

按照“:”分割后的第三列倒序排序

本次分享到这里就结束了,希望对大家有所帮助。
边栏推荐
- 隐私计算 FATE - 离线预测
- Big God explains open source buff gain strategy live lecture
- Smart supplier management system for chemical manufacturing industry deeply explores the field of supplier management and improves supply chain collaboration
- Introduction to deep learning in machine learning
- 信创操作系统--麒麟Kylin桌面操作系统 (项目十 安全中心)
- MongoDB 在腾讯零售优码中的应用
- 机器学习之深度学习卷积神经网络,实现基于CNN网络的手写字体识别
- 3. caller service call - dapr
- Experiment 6 8255 parallel interface experiment [microcomputer principle] [experiment]
- Visual Studio 2010 编绎Qt5.6.3
猜你喜欢

CODING DevOps 助力中化信息打造新一代研效平台,驱动“线上中化”新未来

Among US private server setup

Visual Studio 2010 配置和使用Qt5.6.3

信创操作系统--麒麟Kylin桌面操作系统 (项目十 安全中心)

What are the most powerful small and medium-sized companies in Beijing?

【初学者必看】vlc实现的rtsp服务器及转储H264文件

一种跳板机的实现思路

Coding Devops helps Sinochem information to build a new generation of research efficiency platform and drive the new future of "online Sinochem"

How to build a 100000 level QPS large flow and high concurrency coupon system from zero

Flutter simply implements multilingual internationalization
随机推荐
Do not use short circuit logic to write STL sorter multi condition comparison
Go zero micro Service Practice Series (VII. How to optimize such a high demand)
Fleet |「後臺探秘」第 3 期:狀態管理
VC2010 编绎Qt5.6.3 提示 CVTRES : fatal error CVT1107:
Flutter简单实现多语言国际化
The world has embraced Web3.0 one after another, and many countries have clearly begun to seize the initiative
Grand launch of qodana: your favorite CI code quality platform
The Web3.0 era is coming. See how Tianyi cloud storage resources invigorate the system to enable new infrastructure (Part 1)
Visual Studio 2019软件安装包和安装教程
【高并发基础】MySQL 不同事务隔离级别下的并发隐患及解决方案
Notes to distributed theory
Innovation and upgrading of supply chain system driven management mode in petrochemical industry and strengthening internal management of enterprises
Soliciting articles and contributions - building a blog environment with a lightweight application server
抖音实战~我关注的博主列表、关注、取关
ROS knowledge points - build an ROS development environment using vscode
Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
零钱兑换(动态规划)
Xinchuang operating system -- kylin kylin desktop operating system (project 10 security center)
Flutter simply implements multilingual internationalization
Jenkins的安装及使用