博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
shell特殊符号、cut命令、sort_wc_uniq命令、tee_tr_split命令、shell特殊符号下
阅读量:6881 次
发布时间:2019-06-26

本文共 2053 字,大约阅读时间需要 6 分钟。

shell特殊符号

* 任意个任意字符

[root@test ~]# ls *.txt

1.txt  23.txt  2.txt  david.txt

? 任意一个字符

[root@test ~]# ls ?.txt

1.txt  2.txt

# 注释字符

[root@test ~]# #echo 'ok'

\ 脱义字符

[root@test ~]# echo -e '123\n456\n789\t0000'

123

456

789 0000

| 管道符

[root@test ~]# cat 2.txt|wc -l

2

cut命令

-b 指定第几个字节

-d 分隔符 

-f 指定段号   

-c 指定第几个字符;若是中文字符等于3个字节c=3b;英文c=b

[root@test ~]# cat 2.txt

I am linux my qq 1234567

[root@test ~]# cat 2.txt|cut -b 1,2,3,4

I am

[root@test ~]# cat 2.txt|cut -c 1,2,3,4

I am

中文的区别

[root@test ~]# cat 1.txt 

我是   linux

[root@test ~]# cat 1.txt|cut -c 1

[root@test ~]# cat 1.txt|cut -b 1,2,3

例子2:打印出linux my

[root@test ~]# cat 2.txt

I am linux my qq 1234567

[root@test ~]# cat 2.txt|cut -d ' ' -f 3,4

linux my

sort_wc_uniq命令

-n 按照数值排序 升序

-r  倒序

-u 排除重复的行

[root@test ~]# sort -n 2.txt

0

0

0

1

1

2

2

3

4

45

56

56

66

87

687

-r:倒序

[root@test ~]# sort -r 2.txt

87

66

56

56

45

4

去重:

[root@test ~]# sort -un 2.txt

0

1

2

3

4

45

56

66

87

-t 表示以:为分隔符; -k3 表示以第3段排序

[root@test ~]# sort -n -t : -k3 3.txt 

pear:90:2.3

apple:10:2.5

orange:20:3.4

banana:30:5.5

wc -l 统计文件行数

wc -c 统计字符数

wc -w 统计单词数

uniq

uniq -d:仅显示重复出现的行

uniq -u:显示不重复出现的行

uniq -c:计算个数

[root@test ~]# cat test.log

https://www.taobao.com/1.html

https://www.taobao.com/2.html

https://www.taobao.com/3.html

https://www.taobao.com/2.html

https://www.baidu.com/inyydex.html

https://www.baidu.com/in.html

https://www.baidu.com/index.html

https://jusjuu.ia/jsw/zdnst/index.html

[root@test ~]# awk -F '[:/]+' '{print $2}' test.log |uniq

www.taobao.com

www.baidu.com

jusjuu.ia

[root@test ~]# awk -F '[:/]+' '{print $2}' test.log |uniq -c

      4 www.taobao.com

      3 www.baidu.com

      1 jusjuu.ia

[root@test ~]# awk -F '[:/]+' '{print $2}' test.log |uniq -d

www.taobao.com

tee_tr_split命令

tree:

tee 和>类似,重定向的同时还在屏幕显示

tr

替换字符

[root@test ~]# echo "HELLO WORLD" | tr 'A-Z' 'a-z'

-d:删除

[root@test ~]# echo "HELLO 123 WORLD12 12" | tr -d [0-9]

HELLO  WORLD 

[root@test ~]# echo "HELLO:123 WORLD:12 " | tr -s ":" "="

HELLO=123 WORLD=12

split

切割;

-b大小(默认单位字节)

-l行数

本文转自方向对了,就不怕路远了!51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1978798 ,如需转载请自行联系原作者
你可能感兴趣的文章
linux中的内存
查看>>
Linux查看磁盘挂载信息和卸载方式
查看>>
maven 乱码处理
查看>>
mapreduce文件读取与清洗
查看>>
topcoder Single Round 624(500)
查看>>
字符串匹配的Boyer-Moore算法
查看>>
Memcache 简单操作
查看>>
获取微信用户信息
查看>>
CentOS 7修改网络接口名称
查看>>
Javascript博客转载集合
查看>>
ActiveMQ学习笔记06 - 消费者负载均衡与高可用
查看>>
servlet线程不安全的实例已及解决办法
查看>>
logstash使用
查看>>
Oracle从表的中文注释创建中文视图
查看>>
eclipse_集成Properties_Editor
查看>>
Android平台最新开发技术发展和更新的介绍
查看>>
mark~ iOS消除对应的警告!之代码洁癖
查看>>
Popover TableViewCell
查看>>
DAAnisotropicImage
查看>>
【分布式事务系列四】分布式事务的概念
查看>>