zoukankan      html  css  js  c++  java
  • Linux bash sed 常用方法

    Linux bash sed 常用方法

    #! /bin/bash
    
    
    ####################################################################################################
    ####################################################################################################
    #找到指定行,并将指定行的下面20行注释 “//”, 指定行的下面20行,每行开头插入“//”
    
    line_num=1
    
    cat /home/cjl/test.c | while read line
    do
        # echo $line
    	line_num=$(($line_num+1))
    	if [[ $line == "//set task group" ]]; then sed -i "${line_num},+20 s/^////g" /home/cjl/test.c;fi
    done
    
    
    ####################################################################################################
    ####################################################################################################
    #编译驱动
    
    cd /home/cjl/0608/sdk/drv/ 
    make 
    sleep 1
    
    echo "1111" | sudo -S commonds    ##  sudo 命令 免输入密码
    echo "1111" | sudo -S commonds  
    
    result0=$(ps -aux|grep "key")   ## 检查命令结果
    
    if [ ! -n "$result0" ]; then
    echo "insert modified driver fail!"
    else
    echo "insert modified driver successful!"
    fi 
    
    echo "1111" | sudo -S  mtool w.l 0xd8080000 0xffffffff
    echo "1111" | sudo -S  mtool w.l 0xd8080048 0x00000000
    
    cd /home/cjl/0608/example/
    make 
    sleep 1
    
    ./hello_world&   ## 程序后台运行
    
    sleep 2
    ps -efww | grep -w 'hello_world' | grep -v grep | cut -c 10-14 | xargs kill -9   ## 按照程序名找到进程ID ,按照进程ID kill 进程
    sleep 2
    
    result1=$(dmesg |grep breakdown)   
    
    echo $result1
    
    if [ ! -n "$result1" ]; then
    echo " OK!"
    else
    echo "breakdown!"
    fi 
    
    echo "prepare to reset breakdown"
    reset command
    
    sleep 2
    
    result2=$("check reset command"|grep STOP)
    if [ ! -n "$result2" ]; then
    echo "reset sucessful!"
    else
    echo "reset fail!"
    fi 
    
    
    ####################################################################################################
    ####################################################################################################
    #指定文件的指定行的下面20行,删掉下面行每行开头两个字符
    line_num=1
    
    cat /home/cjl/test.c | while read line
    do
         # echo $line
      line_num=$(($line_num+1))
      if [[ $line == "//set task group" ]]; then sed -i "${line_num},+20 s/..//" /home/cjl/test.c;fi
    
    done
    
    
  • 相关阅读:
    时钟同步
    通过 profiling 定位 golang 性能问题
    览器全面禁用三方 Cookie 全栈前端精选 4月16日
    为什么Go自带的日志默认输出到os.Stderr?
    gRPC Motivation and Design Principles | gRPC https://grpc.io/blog/principles/
    应用安全开发指南
    Hash Join: Basic Steps
    Building a high performance JSON parser
    阿姆达尔定律 Amdahl's law
    贝壳找房小程序平台架构演进
  • 原文地址:https://www.cnblogs.com/michaelcjl/p/14870402.html
Copyright © 2011-2022 走看看