Stream Editor - Pattern Buffer


The basic operation that we perform on any file displays its contents. So we can print the command that prints the content of pattern buffer.


\\Now we are creating a file containing line number, book name, its author.

$ vi lfc.txt 


1) The Shadow of the Wind,  Carlos Ruiz Zafón
2) One Hundred Years of Solitude,  Gabriel García Márquez 
3) The Little Prince ,  Antoine de Saint
4) The Alchemist, Paulo Coelho 

----------------------------------------------
----------------------------------------------

\\let us print the file contents.


$ sed 'p' lfc.txt

1) The Shadow of the Wind,  Carlos Ruiz Zafón
1) The Shadow of the Wind,  Carlos Ruiz Zafón
2) One Hundred Years of Solitude,  Gabriel García Márquez 
2) One Hundred Years of Solitude,  Gabriel García Márquez 
3) The Little Prince ,  Antoine de Saint
3) The Little Prince ,  Antoine de Saint
4) The Alchemist, Paulo Coelho 
4) The Alchemist, Paulo Coelho 


As you have seen, each line is printed twice. If you remember the workflow of SED then by default, SED prints the contents of the pattern buffer and we also include the print command so that the content prints twice.

So if we use the -n option, the content will not be printed twice due to suppress the default printing of the pattern buffer.


$ sed -n 'p' lfc.txt 


1) The Shadow of the Wind,  Carlos Ruiz Zafón
2) One Hundred Years of Solitude,  Gabriel García Márquez 
3) The Little Prince ,  Antoine de Saint
4) The Alchemist, Paulo Coelho 





Visit :


Discussion


* You must be logged in to add comment.