4个我经常滥用的unix命令

本文介绍了几种实用的Shell命令技巧,包括使用grep进行文件内容搜索、利用more与cat结合显示文件内容、通过管道操作筛选并展示特定格式的IP地址等。这些技巧有助于提升日常工作中对文本文件处理的效率。
摘要由CSDN通过智能技术生成

1.grep dot

    

$ grep . *.txt
jack.txt:Once upon a time
jack.txt:there was a fellow named Jack.
lyingryan.txt:Now that "trickle down economics" has been
lyingryan.txt:tested for 30 years and the data shows it
lyingryan.txt:has been a total failure, candidates
lyingryan.txt:still claim that cutting taxes for
lyingryan.txt:billionaires will help the economy.
market.txt:Jack went to market to sell the family
market.txt:cow.
market.txt:He came back with a handful of magic beans.
$

2.more star pipe cat

more * | cat 
::::::::::::::
jack.txt
::::::::::::::
Once upon a time
there was a fellow named Jack.
 
::::::::::::::
lyingryan.txt
::::::::::::::
Now that "trickle down economics" has been
tested for 30 years and the data shows it
has been a total failure, candidates
still claim that cutting taxes for
billionaires will help the economy.
::::::::::::::
market.txt
:::::::::::::::
Jack went to the free-market to sell the family
cow.
He came back with a handful of magic beans.
$
也可以使用head -n 1000 *|cat
3.grep --color=always '^|foo|bar' 等价于grep --color=always '|foo|bar'
$ gnt-job list | egrep --color=always '^|running|waiting'
157486 success CLUSTER_VERIFY_CONFIG
157487 success CLUSTER_VERIFY_GROUP(7ee44802-85d3-40fb-bd36-a7e701ecea29)
157488 success CLUSTER_VERIFY_GROUP(72a2138c-dc07-494d-bd02-ebff7916c9bc)
157489 success CLUSTER_VERIFY_GROUP(457c7377-c83b-4fed-9ebe-a2974e2c521f)
157712 success OS_DIAGNOSE
157779 success CLUSTER_VERIFY
157780 success CLUSTER_VERIFY_CONFIG
157781 success CLUSTER_VERIFY_GROUP(7ee44802-85d3-40fb-bd36-a7e701ecea29)
157782 success CLUSTER_VERIFY_GROUP(72a2138c-dc07-494d-bd02-ebff7916c9bc)
157783 success CLUSTER_VERIFY_GROUP(457c7377-c83b-4fed-9ebe-a2974e2c521f)
157994 success OS_DIAGNOSE
158073 running CLUSTER_VERIFY
158074 success CLUSTER_VERIFY_CONFIG
158075 success CLUSTER_VERIFY_GROUP(7ee44802-85d3-40fb-bd36-a7e701ecea29)
158076 success CLUSTER_VERIFY_GROUP(72a2138c-dc07-494d-bd02-ebff7916c9bc)
158077 success CLUSTER_VERIFY_GROUP(457c7377-c83b-4fed-9ebe-a2974e2c521f)
158156 success OS_DIAGNOSE
158367 success CLUSTER_VERIFY
158368 waiting CLUSTER_VERIFY_CONFIG
158371 success CLUSTER_VERIFY_GROUP(457c7377-c83b-4fed-9ebe-a2974e2c521f)
158432 waiting OS_DIAGNOSE
$
4. "fmt -1" (split lines into individual words)
$ cat *.wiki | fmt -1 | egrep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort -u
192.168.1.4
192.168.1.7
255.255.255.0#
255.255.255.192
255.255.255.240
8.3.8.1
<code>172.16.240.1
<code>172.16.240.2

$ cat *.wiki | tr "#:@;()<>=,'-\"" ' ' | fmt -1 | egrep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | tr -d ' ' | sort -u
172.16.240.1
172.16.240.2
192.168.1.4
192.168.1.7
255.255.255.0
255.255.255.192
255.255.255.240
8.3.8.1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值