In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "if the sed command in linux is replaced," interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "sed command in linux if replacement is implemented"!
Methods: 1. Set parameter "c", c can be followed by strings, these strings can replace the specified line, syntax is " sed 'line number c replaced content'";2. Set parameter"s", you can directly replace the work, syntax is"sed 's/string to be replaced/new string/g'".
Operating environment: Linux 7.3 system, Dell G3 computer.
How to replace sed command in linux
The Linux sed command uses scripts to process text files.
sed can process and edit text files according to script instructions.
Sed is mainly used to edit one or more files automatically, simplify the iterative operation of files, write conversion programs, etc.
syntax
sed [-hnV][-e][-f][text file]
Parameter Description:
-e or--expression= Process the input text file with the script specified in the option.
-f or--file= Process 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 of script processing.
-V or--version Displays version information.
Action Description:
a: new, a can be followed by strings, and these strings will appear in the new line (the current next line)~
c: Replace, c can be followed by strings, these strings can replace the line between n1,n2!
d: Delete, because it is deleted, so there is usually nothing after d;
i: insert, i can be followed by strings, and these strings will appear on a new line (the current line above);
p: Print, i.e. print out selected data. Usually p runs with sed -n ~
S: Substitute, you can directly carry out the replacement work! Usually this action of s can be combined with normal notation! For example, 1,20s/old/new/g is right!
Examples are as follows:
Replace lines 2-5 with "No 2-5 numbers"?
[root@www ~]# nl /etc/passwd | sed '2,5c No 2-5 number'1 root:x:0:0:root:/root:/bin/bashNo 2-5 number6 sync:x:5:0:sync:/sbin:/bin/sync..... (omitted later)...
In addition to the whole row processing mode, sed can also search and replace parts of the data with behavior units. Basically sed search and replace is quite similar to vi! He's kind of like this:
sed 's/string to be replaced/new string/g'
First observe the original information, query IP with/sbin/ifconfig
[root@www ~]# /sbin/ifconfig eth0eth0 Link encap:Ethernet HWaddr 00:90:CC:A6:34:84inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0inet6 addr: fe80::290:ccff:fea6:3484/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1..... (hereinafter omitted)........................
The IP number is 192.168.1.100.
Delete the first part of IP
[root@www ~]# /sbin/ifconfig eth0 | grep 'inet addr' | sed 's/^.* addr://g'192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
Next, delete the following part, namely: 192.168.1.100 Bcast: 192.168.1.255 Mask: 255.255.255.0
Delete the part after IP
[root@www ~]# /sbin/ifconfig eth0 | grep 'inet addr' | sed 's/^.* addr://g' | sed 's/Bcast.*$// g'192.168.1.100 At this point, I believe that everyone has a deeper understanding of "sed command in linux if replacement is implemented," so it is advisable to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue 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.