banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

Linux uses the sed command to perform line operations on files.

title: "Using sed command in Linux for file line operations"
date: "2018-11-09"
categories:

  • "system management"
    tags:
  • "linux"
  • "sed"

  1. Delete the first line of the document: sed -i '1d'
  2. Delete the last line of the document: sed -i '$d'
  3. Add a line after a specified line in the document. For example, if the document is as follows: echo "1"; echo "2"; echo "4"; echo "5"; and you want to add echo "3" after echo "2", you can use the following command: sed -i '/echo "2";/aecho "3";' The use of semicolon is because it already exists in the text. In other words, the semicolon is not necessary! In general, the command is: sed -i '/* /a*'
  4. Delete a specific line in the file: sed -i '3d'
  5. Delete all lines in the file that start with a specific keyword: sed -i '/^QWQ/d'
  6. Delete all lines in the file that contain a specific keyword: sed -i '/QWQ/d'
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.