当前位置:网站首页>Knowing these commands allows you to master shell's own tools
Knowing these commands allows you to master shell's own tools
2022-06-28 16:09:00 【51CTO】
The previous article was case driven , Sum up Sell The basic grammar in , This article takes you through case driven learning Sell The built-in tool commands in .
Cut
cut The job of “ cut ”, Specifically, it is used to cut data in the file .cut Command to cut bytes from each line of a file 、 Characters and fields and put these bytes 、 Character and field output .
Basic usage
Parameter description
- -f : Column number , Extract which column
- -d : Separator , Splits columns according to the specified separator
Case study :
First go to linux In the system , Prepare the data
Case study 1: cutting cat.txt First column
Case study 2: cutting cat.txt second 、 The three column
Case study 3: stay cat.txt Cut out in file lisi
Sed
sed Is a flow editor , It processes one line at a time . When dealing with , Store the currently processed rows in a temporary buffer , be called “ Mode space ”, Then use sed Command processing buffer contents , After processing , Send the contents of the buffer to the screen . Next line , This is repeated , Until the end of the file . The contents of the document have not changed , Unless you use redirected storage output .
Basic usage
Parameter description
- -e : Directly in command line mode sed Action editor
Command function
- a : newly added ,a You can use a string after , On the next line
- d : Delete
- s : Find and replace
Case study :
Prepare the data
Case study 1: take “hello wawa” This word is inserted into sed.txt Second elements , Print
ps: The file hasn't changed
Case study 2: Delete sed.txt All files contain wo The line of
Case study 3: take sed.txt In file wo Replace with ni
Awk
A powerful text analysis tool , Read the document line by line , Slice each line with a space as the default separator , The cut part is analyzed again .
Basic usage
Parameter description
- -F : Specify the input file separator
- -v : Assign a user-defined variable
Case study :
Prepare the data
Search for passwd Document to root All lines at the beginning of the keyword , And output the 7 Column .
awk Built in variables for
- FILENAME file name
- NR Number of records read
- NF The number of fields in the browsing record ( After cutting , Number of columns )
Case study :
Statistics passwd file name , Line number of each line , Columns per row
Sort
sort The order is in Linux It's very useful , It sorts the files , And output the sorting result standard .
Basic grammar
Parameter description
- -n Sort by the size of the value
- -r In reverse order
- -t Set the separator used for sorting
- -k Specify the columns to sort
Case study :
Prepare the data
according to “:” The third column after splitting is sorted in reverse order
This sharing ends here , I hope that's helpful .
边栏推荐
- Fleet |「後臺探秘」第 3 期:狀態管理
- ID卡复制教程(使用T5577卡复制4100卡)
- Installation and use of Jenkins
- What is the difference between treasury bonds and time deposits
- QT create 5.0.3 configuring qt4.8.7
- Flutter simply implements multilingual internationalization
- 【MySQL】官网文档学习之查询语句sql注意事项
- Openharmony - detailed source code of Kernel Object Events
- [high concurrency foundation] hidden dangers and solutions of MySQL concurrency under different transaction isolation levels
- 使用Karmada实现Helm应用的跨集群部署
猜你喜欢
【MySQL】表连接为什么比子查询快
5分钟的时间制作一个反弹球游戏
Lecturer solicitation order | Apache dolphin scheduler meetup sharing guests, looking forward to your topic and voice!
OpenHarmony—内核对象事件之源码详解
【Proteus仿真】L297驱动步进电机
一台服务器最大并发 tcp 连接数多少?65535?
A new 25K byte from the Department showed me what the ceiling is
【推荐系统】多任务学习之ESMM模型(更新ing)
[leetcode] 13. Roman numeral to integer
大神详解开源 BUFF 增益攻略丨直播讲座
随机推荐
The past and present life of distributed cap theorem
OpenHarmony—内核对象事件之源码详解
Big God explains open source buff gain strategy live lecture
一种跳板机的实现思路
In depth learning foundation summary
全球陆续拥抱Web3.0,多国已明确开始抢占先机
IPDK — Overview
【Spock】处理 Non-ASCII characters in an identifier
【Proteus仿真】L297驱动步进电机
Qt5.5.1配置MSVC2010编绎器和windbg调试器
平台即代码的未来是Kubernetes扩展
关于针对tron API签名广播时使用curl的json解析问题解决方案及针对json.loads方法的问题记录
隐私计算 FATE - 离线预测
Today's sleep quality record is 80 points
Introduction to deep learning in machine learning
[MySQL] official website document learning query statement SQL precautions
零钱兑换(动态规划)
机器学习之深度学习卷积神经网络,实现基于CNN网络的手写字体识别
【LeetCode】13、罗马数字转整数
Coding Devops helps Sinochem information to build a new generation of research efficiency platform and drive the new future of "online Sinochem"