In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use linux sed, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Sed is a non-interactive editor. It does not modify the file unless you use shell redirection to save the results. By default, all output lines are printed to the screen.
An example of using Sed to make text file changes
Suppose you have a file called linuxidc.com.txt that contains the following lines:
1, linuxidc, Title 639, Price 5.903, linuxmi nihao, Title 880, Price 1.305, Johnny Cash, Title 582, Price 9.307, John Lennon, Title 571, Price 7.509, linuxidc com, Title 585, Price $1.80
You want to change all price changes from $9.30 to $8.88. You can do this by using the sed command in the following ways:
Linuxidc@Ubuntu:~/linuxidc.com$ sed's linuxidc.com.txt 9.30 Compact 8.88 Universe > linuxidc.txt
This code makes changes and saves the modified file as linuxidc.txt. The new file generated contains:
Linuxidc@ubuntu:~/linuxidc.com$ cat linuxidc.txt1, linuxidc, Title 639, Price $8.882, linuxidc ninhao, Title 761, Price $5.903, linuxmi nihao, Title 880, Price $8.884, linuxmi com, Title 1988.Price $1.305, Johnny Cash, Title 582, Price $6.506, Elvis Presley, Title 370, Price $8.887, John Lennon, Title 571, Price $8.908, Michael Jackson, Title 673, Price $7.509, linuxidc com, Title 585, Price $1.80
Sed command simple use of sample sharing sed command simple use of sample sharing
If you want to replace all occurrences of "linuxmi" with "linuxidc", you can also use the sed command in this way:
Linuxidc@ubuntu:~/linuxidc.com$ sed's Universe Linuxmi Union linuxidc linuxidc@ubuntu:~/linuxidc.com$ sed 'linuxidc.com.txt > linuxidc.txt
The generated modification file linuxidc.txt will contain the following text:
Linuxidc@ubuntu:~/linuxidc.com$ cat linuxidc.txt1, linuxidc, Title 639, Price $9.302, linuxidc ninhao, Title 761, Price $5.903, linuxidc nihao, Title 880, Price $9.304, linuxidc com, Title 1988.Price $1.305, Johnny Cash, Title 582, Price $6.506, Elvis Presley, Title 370, Price $9.307, John Lennon, Title 571, Price $8.908, Michael Jackson, Title 673, Price $7.509, linuxidc com, Title 585, Price $1.80 use Sed commands to filter
Sed is also often used to filter lines in a file. For example, if you only want to view lines that contain "linuxidc", you can use the following sed command:
Linuxidc@ubuntu:~/linuxidc.com$ sed-n'/ linuxidc/p' linuxidc.com.txt > linuxidc.txt
The new linuxidc.txt file will contain the following lines:
Linuxidc@ubuntu:~/linuxidc.com$ cat linuxidc.txt2, linuxidc ninhao, Title 761, Price $5.909, linuxidc com, Title 585, Price $1.80Thank you for reading this article carefully. I hope the article "how to use linux's sed" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.