linux个人学习的一点记录(6) shell中字符的处理

本文介绍了 Linux Shell 下常用的文本处理命令,如 head、tail、wc、uniq 和 paste 等,展示了如何利用这些工具进行文件内容查看、统计、去重及合并等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

linux shell里字符的处理

head
tail

wc README
207 1923 13011 README
line words character
wc -l
wc -w
wc -c

uniq unique的缩写,将相邻的重复行去除 ::uniq file1
sort -u 先排序,再将相邻的重复行删除,-u 表示unique
uniq -c 可以发现出现重复的共有几行

paste 将几个不同文件内容放一起,各个文件行的水平放置,每个文件的行用Tab分割
user1:/home/xuser1>paste testvi1 testvi2 testvi3 >tests
user1:/home/user1>cat tests
test1 test2 test3

user1:/home/user1>cat testvi1 testvi2 testvi3 >tests2
user1:/home/user1>cat tests2
test1
test2
test3


tr 字符转义器
tr 'A-Z' 'a-z' < .bash_profile
将.bash_profile中大写的A-Z转成小写的a-z

unix $ --> Dos \r
cat -A file1 显示所有文件内容,包括回车
cat -A tests2 |tr '$' '\r' >tests3

dos2unix 、unix2dos 也可做这些

diff 比较文件
< 第一个文件
> 第二个文件

sdiff file1 file2 更方便阅读

aspell 检查英文单词拼写是否正确
aspell check file1
look命令快速查询单词拼写是否正确
look exer


format字符串的一些命令
expand 将Tab转换成空格

fmt 格式化段落 -u统一的空格设定 -w设定列宽度
fmt -u -w50 file1

pr 按打印机格式格式化
pr /usr/share/dict/words |more
pr -5 /usr/share/dict/words |more 每行5列
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值