zoukankan      html  css  js  c++  java
  • 实用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等脚本语言使用。
  • 相关阅读:
    js问题记录
    css问题记录
    vscode配置java+gradle开发环境
    js插件
    nginx笔记
    vue刷新当前路由
    koa踩坑记录
    react踩坑笔记
    ts踩坑笔记
    vue源码阅读笔记
  • 原文地址:https://www.cnblogs.com/accipiter/p/7052387.html
Copyright © 2011-2022 走看看