zoukankan      html  css  js  c++  java
  • shell 处理文件脚本

    [root@centos-6 ~]# cat info_file.txt 
    lys:28:shanxi
    zhy:28:shanxi
    [root@centos-6 ~]# cat info_file2.txt 
    lys 28 shanxi
    zhy 28 shanxi
    [root@centos-6 ~]# cat print.sh 
    #!/bin/bash
    for i in `cat info_file.txt`
    
    do
    
    
    
    name=$(echo $i |awk -F : '{print $1}')
    age=$(echo $i |awk -F : '{print $2}')
    address=$(echo $i |awk -F : '{print $3}')
    
    echo "$name | $age |  $address "
    done
    [root@centos-6 ~]# cat while.sh 
    #!/bin/bash
    
    while read a b c
    
    do
    
    echo $a $b $c
    
    done <info_file2.txt
    [root@centos-6 ~]# sh print.sh 
    lys | 28 |  shanxi 
    zhy | 28 |  shanxi 
    [root@centos-6 ~]# sh while.sh 
    lys 28 shanxi
    zhy 28 shanxi
    [root@centos-6 ~]# 
    
    [root@centos-6 ~]# cat shift.sh 
    #!/bin/bash
    
    echo "print $1"
    
    [ "$1" = "lys" ] && shift 
    
    
    echo "print $1"
    
    ping -c 2 $1
    [root@centos-6 ~]# sh shift.sh  lys www.baidu.com
    print lys
    print www.baidu.com
    PING www.a.shifen.com (14.215.177.37) 56(84) bytes of data.
    64 bytes from 14.215.177.37: icmp_seq=1 ttl=128 time=147 ms
    64 bytes from 14.215.177.37: icmp_seq=2 ttl=128 time=144 ms
    
    --- www.a.shifen.com ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 5315ms
    rtt min/avg/max/mdev = 144.476/146.061/147.646/1.585 ms
    [root@centos-6 ~]# ^C
    [root@centos-6 ~]# sh shift.sh  zht www.baidu.com
    print zht
    print zht
    ping: unknown host zht
    [root@centos-6 ~]# 
    
  • 相关阅读:
    Python Request快速入门
    python 集合比较(交集、并集,差集)
    Python正则表达式详细应用
    Python的os.walk()方法详细讲解
    selenium 常用小方法
    .NET实体框架EF之CodeFirst
    Jenkins报错Cannot run program "sh"
    git生成ssh
    win7下docker环境安装
    JS时间转换,url编码,jquery返回类型等问题
  • 原文地址:https://www.cnblogs.com/liuyoushui/p/6595752.html
Copyright © 2011-2022 走看看