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 ~]# 
    
  • 相关阅读:
    linux目录跳转的好武器z.sh
    找工作的程序员必懂的Linux
    11-面向对象4
    10-面向对象3
    09-面向对象2
    08-面向对象1
    06-数组
    3.5-乘法运算器设计
    3.2-定点数补码加减运算器设计
    4.12-虚拟存储器
  • 原文地址:https://www.cnblogs.com/liuyoushui/p/6595752.html
Copyright © 2011-2022 走看看