Blogger Information
Blog 110
fans 0
comment 0
visits 112304
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Linux下的sed,和awk命令使用分析
Coco
Original
657 people have browsed it

  使用sed命令编辑文件

  //删除第一行

  $>sed '1d' 1.log

  //删除最后一行

  $>sed '$d' 1.log

  //删除区间行

  $>sed '1,3d' 1.log

  //删除所有行

  $>sed '1,$d' 1.log

  //p:print

  $>sed '1,$p' 1.log

  //-n:安静模式,只显示处理的行

  $>sed -n '1,$p' 1.log

  //-i:对源文件进行修改

  $>sed -i '1,$p' 1.log

  //显示含有hello的行

  $>sed -n '/hello/p' 1.log

  //追加内容

  $>sed -i '1ahello' 1.log

  //追加新行,指定前置字符

  $>sed -i '1a\ hello' 1.log

  //每行都追加hello

  $>sed -i '1,3ahello' 1.log

  //替换,针对整行

  $>sed -i '1,2ckkk' 1.log

  //替换,针对特定字符串,用how替换掉hello

  $>sed -i 's/hello/how/g' 1.log

  脚本例子:

  exec.sh

  #!/bin/bash

  systime=`date -d "-3 minute" +%Y%m-%d-%H%M`

  ym=`echo ${systime} | awk -F '-' '{print $1}'`

  sed -i 's/${day}/'${day}'/g' ~/Downloads/exportData.sql

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post