shell特殊符号、cut命令、sort_wc_uniq命令、tee_tr_split命令、shell特殊符号下

简介:

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

www.baidu.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行数










本文转自 iekegz 51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1978798,如需转载请自行联系原作者
目录
相关文章
|
6天前
|
Shell 程序员 数据安全/隐私保护
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
|
18天前
|
网络协议 Unix Shell
第十一章 Shell常用命令与工具(二)
第十一章 Shell常用命令与工具(二)
|
18天前
|
移动开发 Shell Linux
第十一章 Shell常用命令与工具(一)
第十一章 Shell常用命令与工具(一)
|
23天前
|
存储 Shell 数据安全/隐私保护
ZooKeeper【基础知识 04】控制权限ACL(原生的 Shell 命令)
【4月更文挑战第11天】ZooKeeper【基础知识 04】控制权限ACL(原生的 Shell 命令)
27 7
|
24天前
|
Shell
ZooKeeper【基础 02】zookeeper-3.6.0 常用Shell命令(节点增删改查+监听器+四字指令)
【4月更文挑战第10天】ZooKeeper【基础 02】zookeeper-3.6.0 常用Shell命令(节点增删改查+监听器+四字指令)
25 0
|
1月前
|
分布式计算 Hadoop Shell
Hadoop【基础知识 04】【HDFS常用shell命令】(hadoop fs + hadoop dfs + hdfs dfs 使用举例)
【4月更文挑战第4天】Hadoop【基础知识 04】【HDFS常用shell命令】(hadoop fs + hadoop dfs + hdfs dfs 使用举例)
33 5
|
1月前
|
Shell Linux
在linux shell脚本中root切换到普通用户执行脚本或命令的方法
在linux shell脚本中root切换到普通用户执行脚本或命令的方法
13 1
|
1月前
|
Shell
shell学习(三)【shell变量、数组,文件命令、特殊变量】
shell学习(三)【shell变量、数组,文件命令、特殊变量】
14 0
|
1月前
|
Shell
shell 命令(一)概述【别名、 bash重定向 、定义变量】
shell 命令(一)概述【别名、 bash重定向 、定义变量】
23 0
|
1月前
|
监控 数据可视化 Unix
自用的Linux命令高效的4个shell替代工具
这篇文章介绍了几个用于提升Unix系统终端体验的替代工具。首先提到了`oh-my-zsh`,然后重点推荐了三个命令行工具:1) `htop`和`btop`作为`top`命令的增强版,提供更丰富的进程监控视图;2) `duf`作为`df`命令的替代,以更整洁的界面显示磁盘空间使用情况;3) `eza`(原`exa`)和`bat`,这两个工具为`ls`和`cat`命令提供了颜色高亮和更好的文件查看体验。这些工具旨在使终端操作更加直观和愉快。
21 0