1、各种文本工具
三剑客:grep、sed、awk抽取文本工具:
文件内容:less 和 cat
文件截取:head和tail
按列抽取:cut
按关键字抽取:grep
(1)cat 文件查看

cat hello.txt (全部展示)

cat -n hello.txt (对所有行加上编号)

cat -sn hello.txt (合并多行空格)

cat -b hello.txt (对非空格行编号)

cat -E hello.txt (显示行的行结束符)

(2)tac
对cat行的反向输出,rev逆反

追加
使用>>指令向文件追加内容,原内容将保存。


(3)more和less



(4) head和hail

输出随机数
cat /dev/urandom
随机输出10个数字和字母
cat /dev/urandom |tr -dc 'a-zA-Z0-9'|head -c 10

ifconfig是linux中用于显示或配置网络设备(网络接口卡)的命令
ifconfig 查看网络设备名称
ifconfig 查看网络设备配置
(5) cut 和Paste
cut

Linux bc 命令可以很方便的进行浮点运算,当然整数运算也不再话下。
bc 甚至可以称得上是一种编程语言了,它支持变量、数组、输入输出、分支结构、循环结构、函数等基本的编程元素
df命令用于显示目前在 Linux 系统上的文件系统磁盘使用情况统计。

df |cut -c 43-46

Linux tr命令

df |tr -s ' ' : |cut -d : -f 5

练习:通过ifconfig获取IP

ifconfig ens33 |head -2 | tail -1 |tr ' ' :|cut -d: -f10

或以空格分开
student@student-virtual-machine:~/Desktop$ ifconfig ens33 |head -2 | tail -1 |cut -d" " -f10
192.168.132.128
或以t,n为分隔符
ifconfig ens33 |head -2 |tail -1 |cut -dt -f2|cut -dn -f1
或 通过排除非数字和点组成的
ifconfig ens33 |head -2 |tail -1 |tr -dc '[0-9]. '|tr -s ' '|cut -d" " -f2
paste

纵向合并
cat f1,f2
横向
paste f1,f2




wc











