当前位置:网站首页>文件内容浏览cut、uniq、sort、tr命令的使用,
文件内容浏览cut、uniq、sort、tr命令的使用,
2022-07-31 05:18:00 【m0_59138290】
文章目录
文件内容浏览
a.cat查看/etc/passwd文件内容,且输出时带行号
[[email protected] ~]# cat -n /etc/passwd
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
4 adm:x:3:4:adm:/var/adm:/sbin/nologin
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8 halt:x:7:0:halt:/sbin:/sbin/halt
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10 operator:x:11:0:operator:/root:/sbin/nologin
b.使用more/less查看/etc/passwd内容,且每页显示10行
[[email protected] ~]# moer -10 /etc/passwd
[[email protected] ~]# less -10 /etc/passwd
c.使用head/tail分别查看文件前5行内容和后5行内容
[[email protected] ~]# head -5 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[[email protected] ~]# tail -5 /etc/passwd
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:975:975::/run/gnome-initial-setup/:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rhcsa:x:1000:1000:rhcsa:/home/rhcsa:/bin/bash
d.使用grep查看/etc/passwd中和root相关的内容
[[email protected] ~]# grep -i root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
cut命令使用:
给定文件cut_data.txt且内容为:
No Name Score
1 zhang 20
2 li 80
3 wang 90
4 sun 60
使用默认定界符切割文件内容,且输出切割后的第一个字段
[[email protected] ~]# cut -d" " -f1 cut_data.txt
No
1
2
3
4
切割文件内容,且输出切割后的第一个字段和第三个字段
[[email protected] ~]# cut -d" " -f1,3 cut_data.txt
No Score
1 20
2 80
3 90
4 60
按字节切割:输出切割的第一个字节到第10个字节的内容
[[email protected] ~]# cut -b 1-10 cut_data.txt
No Name Sc
1 zhang 20
2 li 80
3 wang 90
4 sun 60
按字符切割:输出切割后的第一个字符和第5个字符的内容
[[email protected] ~]# cut -c 1-5 cut_data.txt
No Na
1 zha
2 li
3 wan
4 sun
按指定分界符去切割:内容如下, 输出第一个字段和第三个字段内容
No|Name|Score
1|zhang|20
2|li|80
3|wang|90
4|sun|60
[[email protected] ~]# cut d"|" -f 1,3 cut_data.txt
uniq命令使用: 新建文件uniq_data.txt,文件内容为
Welcome to Linux
Windows
Windows
Mac
Mac
Linux
使用uniq命令输出去重后的结果
[[email protected] ~]# uniq uniq_data.txt
Welcome to Linux
Windows
Mac
Linux
使用uniqmingl只输出重复的行
[[email protected] ~]# uniq -d uniq_data.txt
Windows
Mac
使用uniq命令输出不重复的行
[[email protected] ~]# uniq -u uniq_data.txt
Welcome to Linux
Linux
使用uniq命令统计重复次数
[[email protected] ~]# uniq -c uniq_data.txt
1 Welcome to Linux
2 Windows
2 Mac
1 Linux
sort命令:给定文件 num.txt, args.txt
文件内容:num.txt
1
3
5
2
4
文件内容:args.txt
test
args1
args2
args4
args4
args3
对num.txt进行排序,且将结果输出到sorted_num.txt中
[[email protected] ~]# sort args.txt >> sorted_args.txt
[[email protected] ~]# more sorted_args.txt
args1
args2
args3
args4
args4
test
对args.txt进行排序,且将结果输出到sorted_args.txt中
[[email protected] ~]# more sort_args.txt
args1
args2
args3
args4
args4
test
对num.txt和args.txt进行排序,且将结果输出到sorted_merge.txt中
[[email protected] ~]# sort -n args.txt num.txt >> sorted_merge.txt
[[email protected] ~]# more sorted_merge.txt
args1
args2
args3
args4
args4
test
1
2
3
4
5
对args.txt排序后去重输出
[[email protected] ~]# sort -u args.txt
args1
args2
args3
args4
test
合并sorted_args.txt和sorted_num.txt且输出
[[email protected] ~]# cat sorted_args.txt >> sorted_num.txt
[[email protected] ~]# more sorted_num.txt
给定文件info_txt:按第二列作为key进行排序
No Name Score
1 zhang 20
2 li 80
3 wang 90
4 sun 60
[[email protected] ~]# vim info_txt
[[email protected] ~]# sort -t" " -k2 info_txt
2 li 80
No Name Score
4 sun 60
3 wang 90
1 zhang 20
将26个小写字母的后13个字母替换成大写字母
[[email protected] ~]# echo "abcdefghijklmnopqrstuvwxyz" | tr n-z N-Z
abcdefghijklmNOPQRSTUVWXYZ
将hello 123 world 456中的数字替换成空字符
[[email protected] ~]# echo "hello 123 world 456" | tr 1-6 " "
hello world
将hello 123 world 456中字母和空格替换掉,只保留数字
[[email protected] ~]# echo "hello 123 world 456" | tr -c 1-6 " "
123 456 [[email protected] ~]#
边栏推荐
- vs2022 xlua 集成第三方库编译报错Generator Visual Studio 15 2017 could not find any instance of Visual Studio.
- 安装显卡过程中遇到问题汇总
- 911崩了,自养号测评环境IP有哪些更好的选择
- 力扣.三数之和/四数之和
- CLS-PEG-FITC Fluorescein-PEG-CLS 胆固醇-聚乙二醇-荧光素简介
- 学习JDBC之获取数据库连接的方式
- cenos7配置IP,配置IP不生效
- Cholesterol-PEG-DBCO Cholesterol-Polyethylene Glycol-Diphenylcyclooctyne Chemical Reagent
- 2021年开发人员的绊脚石:构建时间长
- 5G的用途和工作原理
猜你喜欢

Tensorflow steps on the pit while using it

The content of the wangeditor editor is transferred to the background server for storage

cenos7安装cmake-3.22.2

Learn how to get a database connection with JDBC

会话和饼干,令牌

链表理论基础

Cholesterol-PEG-NHS NHS-PEG-CLS cholesterol-polyethylene glycol-active ester can modify small molecular materials

Unity加载GIf动画

CAS:1403744-37-5 DSPE-PEG-FA 科研实验用磷脂-聚乙二醇-叶酸

DingTalk Enterprise Internal-H5 Micro Application Development
随机推荐
vs2022 xlua 集成第三方库编译报错Generator Visual Studio 15 2017 could not find any instance of Visual Studio.
浅谈音视频开发入门基础及进阶资源分享
Rejection sampling note
解决background-size:cover时图片铺满但显示不完整?
C语言静态变量static
链表理论基础
十分钟教你玩转分支语句!!!!!小白速进,新手福利!!
力扣刷题之排序链表
Tensorflow related list
Unity版本升级问题总结
ROS subscription to multiple topics time synchronization problem
解决nx安装 jtop问题
企业级 DevOps 究竟是什么?
面试总爱问的一个问题,你为什么离职上一份工作?
浏览器中的画中画(Picture-in-Picture)API
在 AWS 上从零开始设置 Incredibuild 构建系统
Cholesterol-PEG-Amine CLS-PEG-NH2 Cholesterol-Polyethylene Glycol-Amino Research Use
Detailed explanation of mysql transaction principle
pyspark.ml feature transformation module
Image binarization processing of opencv