zoukankan      html  css  js  c++  java
  • CentOS 文件中行内容操作

               在指定内容后面新增一行:

    [root@localhost ~]# sed -i.bak '/^1111/a 22222222' a.txt    -- 在以‘1111’开头的行后面加内容为‘22222222’的行
    [root@localhost ~]# ll
    总用量 20
    -rw-------. 1 root root 1117 Mar 25 10:04 anaconda-ks.cfg
    -rw-r--r--  1 root root   35 Jul  6 11:08 a.txt
    -rw-r--r--  1 root root   26 Jul  6 11:07 a.txt.bak
    drwxr-xr-x. 2 root root    6 Mar 25 10:11 Desktop
    drwxr-xr-x. 2 root root    6 Mar 25 10:11 Documents
    drwxr-xr-x. 2 root root    6 Mar 25 10:11 Downloads
    -rw-r--r--. 1 root root 1424 Mar 25 10:05 initial-setup-ks.cfg
    drwxr-xr-x. 2 root root    6 Mar 25 10:11 Music
    drwxr-xr-x. 2 root root    6 Mar 25 10:11 Pictures
    drwxr-xr-x. 2 root root    6 Mar 25 10:11 Public
    -rw-r--r--  1 root root  935 Jun 10 11:08 :q
    drwxr-xr-x. 2 root root    6 Mar 25 10:11 Templates
    drwxr-xr-x. 2 root root    6 Mar 25 10:11 Videos
    [root@localhost ~]# cat a.txt
    111111111
    22222222
    
    111
    
    33333333

             替换某行的内容:

    [root@localhost ~]# sed -i '/^111$/c 55555' a.txt    -- 行内容为‘111’替换成‘55555’
    [root@localhost ~]# cat a.txt
    111111111
    22222222
    
    55555
    
    33333333

         删除某一行内容:

    [root@localhost ~]# sed -i '/^3/d' a.txt   -- 删除以3开头的行
    [root@localhost ~]# cat a.txt
    111111111
    22222222
    
    55555
  • 相关阅读:
    [LeetCode] Maximum Depth of Binary Tree
    C++11中常用的几个简写
    [LeetCode] Word Break
    [LeetCode] Linked List Cycle II
    sizeof
    string和整形数据之间的转换
    ASCII
    [LeetCode] Linked List Cycle
    机器学习总结-线性回归
    推荐系统初探
  • 原文地址:https://www.cnblogs.com/zhongjicainiao/p/14976115.html
Copyright © 2011-2022 走看看