Sed syntax format:
Sed [option] {sed-command} {input-file}
Normally, sed reads the processed rows into the pattern space, and the "sed-command (sed command)" in the script is processed one by one, the script execution is complete. The row is output, and the pattern space is cleared. Then, when the previous action is repeated, the new row in the file is read until the file processing is complete.
However, for various reasons, if you want to retain a command in the script or pattern space under a certain condition for the next use, this may cause sed to not process files according to the normal process. In this case, advanced sed commands must be used to meet the requirements.
Let's talk about command n and command N.
Command n: Read the next line to pattern space. Because pattern space contains the content read according to the normal process, after using the n command, there is another line in pattern space. At this time, pattern space contains two lines of content, however, the row to be read first will not be replaced, overwritten, or deleted. When n is followed by another p command, the output result is the content of the row read by the n command.
Look, you will understand.
Create a file with the following content:
Cat 1.txt
1
2
Normal sed Process
After using the n command,
N command: add the next line to pattern space. The next line that is currently read into the row and added with the N command is regarded as "One Line ".
New File 1.txt
Cat 1.txt
1
2
Normal sed Process
After using the N command
Refer:
Sed and awk Version 2
Have a nice day !!! From http://www.cnblogs.com/fhefh/archive/2011/11/14/2248942.html <script> </script>