I want to find an ip address using shell script by subtracting dnsdomainname from hostname (hostname - dnsdomainname)? - hostname

I want to find an IP address using shell script by subtracting dnsdomainname from hostname (hostname - dnsdomainname) ?
Here is what I have
ip-11-297-183-174.kde.abc.com
How can i retrieve ip address from the above

you can replace the unwanted parts with nothing by using regex to capture the IP address in a capture group. then replace the hyphens with dots. like this ...
$InString = 'ip-11-297-183-174.kde.abc.com'
$OutString = $InString -replace '^ip-(\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}).+$', '$1' -replace '-', '.'
$OutString
output = 11.297.183.174

Related

Extract extension from email address in SQL

I wanted to extract the extension from email address.
Input: test#work.com
Output: com
Input: test#work.test.com
Output: test.com
I tried,
(REVERSE(LEFT(REVERSE('test#work.test.com'), CHARINDEX('.', REVERSE('test#work.test.com')) - 1)))
This works only the first input. Any help?
It seems you want to remove any characters prior to and including the first period (.) after the at symbol (#). I would use CHARINDEX and STUFF for this:
SELECT STUFF(V.Email,1,CHARINDEX('.',V.Email,CHARINDEX('#',V.Email)),'')
FROM (VALUES('test#work.com'),
('test#work.test.com'))V(Email);

redis. how set key name with empty string (not empty value)

I'm making Redis client with swift.
How can i make key name with empty string. (not empty value)
in redis-cli.
I can make key name with empty string.
127.0.0.1:6379> set "" "stringValue"
OK
but, I am using socket to connect Redis server.
and send command, I got error.
telnet 127.0.0.1 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
set "" "stringValue"
-ERR wrong number of arguments for 'set' command
please help me.
You used the inline command to send command to Redis, which does not work with binary data, or data which has 0 length or contains whitespace.
Instead, you should use the more complicated form: *3\r\n$3\r\nset\r\n$0\r\n\r\n$3\r\nval\r\n
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
*3
$3
set
$0
$3
val
+OK

Find IP range with RegEx

I have an input of an IPV4 address and its prefix(from 1-32).
My output should be somthing like:
input:172.194.11.80/24
output: 172.194.11.0-172.194.11.255
I'm doing this via VERTICA (SQL)
My question is this something I should do with RegEx?
Or should I build a function that does this?

What does REST API path "/nfsList/{name:.+}" mean?

name:.+ in the path /nfsList/{name:.+} refers to subnet address.
Is /nfsList/{name:.+} the same as /nfsList/{name}? If not, does {name:.+} have some string format checks for subnet address?
.+ means any charachter including the slash /. So {name:.+} will capture foo/bar in /nfsList/foo/bar.
Without .+, {name} will capture only foo in /nfsList/foo, /nfsList/foo/bar will not match this URL.

How to update only exact value matches?

I am using SQL update query [in powershell script] to update machine name present in column.
The column values are stored as URL. So machine name is part of the string.
( Column Name : URL
Example column value : "http://Machine1:80/Impl100/Core/Data/Config.0")
I am using following query to do the update.
$UpdateQuery="UPDATE [$DatabaseName].[dbo].[$TableName]
SET $columnName=Replace("$ColumnName", '$OldMachineName', '$NewMachineName');"
Assume my old machine name is "Machine1" and i am to replace with "AppMachine1". If i execute the script ,it will update "AppMachine1". But if i execute the script second time It will update it as "AppAppMachine1" as Machine1 is part of AppMachine1.
Is it possible to get the column value and check the machine name before update?
How to do this?
Try this
$UpdateQuery="UPDATE [$DatabaseName].[dbo].[$TableName]
SET $columnName=Replace("$ColumnName", '$OldMachineName', '$NewMachineName')
WHERE "$ColumnName" <> '$NewMachineName';"
Include the double leading forward slashes:
... -replace '//machine1','//AppAppMachine1'
You also need to put quoted variables in double quotes. Single quotes disables variable expansion and as a result variables will no be replaced with its values.
Here's an example of a double replace:
PS> $url = 'http://machine1:80/Impl100/Core/Data/Config.0'
PS> $url -replace '//machine1','//AppAppMachine1' -replace '//machine1','//AppAppMachine1'
http://AppAppMachine1:80/Impl100/Core/Data/Config.0