In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "linux how to delete a line of content", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "linux how to delete a line of content" this article.
In linux, you can use the sed command to delete the specified row, which can replace, delete, add, select, and so on. When the parameter is set to "d", you can delete the contents of the row. The syntax is "sed 'the specified row value that needs to be deleted."
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Sed is a stream editor, it is a very good tool in text processing, can be used perfectly with regular expressions, the function is extraordinary.
When processing, the currently processed line is stored in a temporary buffer, called "pattern space" (pattern space), and then the contents of the buffer are processed with the sed command, and when the processing is completed, the contents of the buffer are sent to the screen. Then process the next line, which is repeated until the end of the file.
The contents of the file have not changed unless you use redirect to store the output. Sed is mainly used to automatically edit one or more files, can replace, delete, add, select and other specific work, simplify the repeated operation of the file, write conversion procedures, and so on.
The Linux sed command uses scripts to process text files.
Sed can process and edit text files according to the instructions of the script.
Sed is mainly used to edit one or more files automatically, simplify the repeated operation of files, write conversion programs, and so on.
The syntax is:
Sed [- hnV] [- e] [- f] [text file]
The parameters are as follows:
-e or-- expression= processes the input text file with the script specified in the option.
-f or-- file= processes the input text file with the script file specified in the option.
-h or-- help displays help.
-n or-- quiet or-- silent displays only the results after script processing.
-V or-- version displays version information.
Action description:
A: added, a can be followed by strings, and these strings will appear on the new line (the current next line) ~
C: instead, c can be followed by strings, which can replace the lines between N1 and N2!
D: delete, because it is deleted, so there is usually no knock after d.
I: insert, I can be followed by strings, and these strings will appear on the new line (the current previous line)
P: print, that is, the selected data is printed out. Usually p runs with the parameter sed-n ~
S: replace, you can directly carry out the work of replacement! Usually the action of this s can be matched with the formal representation! For example, 1Magazine 20s Universe, OldCompact newscop g is it!
Examples are as follows:
List the contents of / etc/passwd and print the line number, and delete line 2-5!
Just delete line 2.
Nl / etc/passwd | sed '2d'
To delete the third to last lines
Nl / etc/passwd | the above are all the contents of the article "how to delete a line of content in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.