title: "Using sed command in Linux for file line operations"
date: "2018-11-09"
categories:
- "system management"
tags: - "linux"
- "sed"
- Delete the first line of the document: sed -i '1d'
- Delete the last line of the document: sed -i '$d'
- 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*'
- Delete a specific line in the file: sed -i '3d'
- Delete all lines in the file that start with a specific keyword: sed -i '/^QWQ/d'
- Delete all lines in the file that contain a specific keyword: sed -i '/QWQ/d'