1. the first is the c \ command in sed. The difference between this command and S/XXX/xxxx/g is that C \ can replace all the rows found by the current sed with the specified text
For example, sed-I "/734/C \ hello" Install. Log, replace the entire line containing a string such as 734 with Hello
When using C \, note that if we add a variable instead of a constant string after the c \ command, we need to add a \ symbol to solve the reference, otherwise, the variable cannot be parsed properly:
Sed-I "/734/C \ $ hello" Install. log -- a row containing 734 is replaced with $ hello
Sed-I "/734/C \ $ hello" Install. log -- a row containing 734 is replaced with the value in the hello variable.
2. there are several good functions, namely converting the IP address to the hexadecimal format, converting the hexadecimal number to the IP address, judging the size of the two IP addresses, and finding the smallest IP address and the largest IP address in a bunch of IP addresses, the command printf is used here. This is a good thing and can be used to format the output. The following code shows printf "% 08x "...... format the following content into a hexadecimal number, with a maximum of 8 digits retained. Iptohex (){
Ifs =.
For STR in $1
Do
Printf "% 02x" $ Str
Done
}
Hextoip (){
Hex = $1
Printf "% d." 0x $ {HEX: 0: 2}
Printf "% d." 0x $ {HEX: 2: 2}
Printf "% d." 0x $ {HEX: 4: 2}
Printf "% d" 0x $ {HEX: 6: 2}
}
Iplarger (){
First = 0x $ (iptohex $1)
Second = 0x $ (iptohex $2)
First = $ (printf "% d" $ first)
Second = $ (printf "% d" $ second)
If [$ first-GT $ second]; then
Return 0
Else
Return 1
Fi
}
Ipsmaller (){
First = 0x $ (iptohex $1)
Second = 0x $ (iptohex $2)
First = $ (printf "% d" $ first)
Second = $ (printf "% d" $ second)
If [$ first-lt $ second]; then
Return 0
Else
Return 1
Fi
}
Find the smallest and largest IP addresses in a bunch of IP addresses (IPaddress is an array ):
Ip_low =$ {IPaddress [1]}
Ip_high = $ ip_low
For ipnow in $ {IPaddress [@]}
Do
If ismasked $ ipnow $ localip $ localmask
Then
If ipsmaller $ ipnow $ ip_low
Then
Ip_low = $ ipnow
Fi
If iplarger $ ipnow $ ip_high
Then
Ip_high = $ ipnow
Fi
Else
Echo IPs not mask
Exit
Fi
Done