实用and常用shell命令汇编

很久没写blog了,基本都在用 github和笔记.现在将一些常用的shell并且很使用的shell用法分享一下:

分行读取,切割,计数:
cat product.txt | while read line ; do  echo $line| cut -d"," -f6 ; done | wc -l
 
所有记录输入到文件里边去:
cat product.txt | while read line ; do  echo $line| cut -d"," -f6 ; done >mobile.txt
 
去重复,排序:
sort mobile.txt | uniq | wc -l
 
判断,条件选择:
cat b_times.txt | while read line;do if [ $line -gt 0 ]; then  echo $line; fi; done
 
求和:
awk '{ sum +=$1 } END { print sum}' b_times_sum.txt
 
 
涉及到非整数比对:
【-bash: [: 0.0: integer expression expected】
 
cat score.txt | while read line;do if [ $line != 0 ]; then echo $line; fi; done | wc -l
 
展开获得的内容:
tail -c +100 2017041808.54.77.47.96 |grep uit2 | head -n 10
 
取字符串的第一个字符:
cat id.txt | while read line ; do  echo ${line:0:1}; done
 
批量关闭进程:
ps -ef | grep spark | awk '{print $2}' | xargs kill -9
 
shell循环:
for i in {40610002..40610010}; do  echo "welcome 13476$i "; done
 
 
curl命令:
 
取字符串长度:
cat result_2017061616_data.txt | while read line; do if [ ${#line} -gt 0 ];then echo $line;fi;done >data.txt
参考:
 
截取字符串:
cat result_2017061616_data.txt | while read line; do if [ ${#line} -gt 0 ];then echo $line;fi;done | cut -c 4-11 >data_test_1.txt
参考:
 
 
##################################################################################
总结,还在不断的补充中,shell是一个非常高效的处理一些事情的工具,当然更多的时候是配合python等脚本语言使用。

转载于:https://www.cnblogs.com/accipiter/p/7052387.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值