您的位置:首页 > 运维架构 > Shell

shell文本处理

2017-01-16 22:28 495 查看
1.文件整理
employee文件中记录了工号和姓名
employee.txt:
100 Jason Smith
200 John Doe
300 Sanjay Gupta
400 Ashok Sharma
bonus文件中记录工号和工资
bonus.txt:
100 $5,000
200 $500
300 $3,000
400 $1,250
要求把两个文件合并并输出如下
处理结果:
400 ashok sharma $1,250
100 jason smith $5,000
200 john doe $500
300 sanjay gupta $3,000

# awk 'ARGIND==1{test[$1]=$0}ARGIND==2{print test[$1],$2}' employee.txt bonus.txt
100 Jason Smith $5,000
200 John Doe $500
300 Sanjay Gupta $3,000
400 Ashok Sharma  $1,250
# cat employee.txt
100 Jason Smith
200 John Doe
300 Sanjay Gupta
400 Ashok Sharma
# cat bonus.txt
100 $5,000
200 $500
300 $3,000
400 $1,250


(2)查看swap分区的大小

# free -m
total       used       free     shared    buffers     cached
Mem:          1001        861        140         18         97        425
-/+ buffers/cache:        338        663
Swap:          509          0        509


(3)root用户今天登陆了多长时间

last查所有登陆信息,

lastlog查看最近登陆,

w或者who查看目前已经登陆用户

(4)打印当前sshd的端口和进程id

# netstat -anp | grep sshd

(5)打印root可以使用可执行文件数

# echo "root’s bins: $(find ./ -type f | xargs ls -l | sed '/-..x/p' | wc -l)"
root’s bins: 53


(6)输出本机创建20000个目录所用的时间

# time for i in {1..2000} ; do mkdir neil$i; done

real    0m2.086s
user    0m0.180s
sys    0m0.300s
[berry@berry:dirs] time

real    0m0.000s
user    0m0.000s
sys    0m0.000s
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: