replace a character in the string using DOS commands - command-line

I have a requirement in which I need to replace particular character from a string, by using a DOS command.
For example, if my string is "1,2,3,4", I need to get the result "1.2.3.4" by replacing each "," with a "." character.

Following will work for you
#echo off
set string1=1,2,3,4
set string2=%string1:,=.%
echo %string2%

This will give you an idea of what to do, not knowing exactly how you get the string to begin with.
set str=1,2,3,4
set str=%str:,=.%

Related

How to remove double Quotes In DataStage using a transformer stage?

We receiving Input data like below
“VENKATA,KRISHNA”
I want output like below
VENKATA,KRISHNA
Can anyone help me with this
Check out the Ereplace function - it allows to replace certain characters so you could rplace " with '' (empty string).
An alternative is TRIM - you can specify which character the command should trim and also if All occurrences or Both (from both sides of the string) plus more.

sqlplus - No characters are allowed after a here-string header but before the end of the line

I'm trying to use sqlplus to do an Oracle query for the first time in a PowerShell script. I get this error message:
At line:1 char:73
+ ... user/pw#RRRPRD.company.net:1521/RRRPRDC #"C:\Users\ ...
+ ~
No characters are allowed after a here-string header but before the end of the line.
It seems to be pointing to the C: after #". Any ideas? I seem to be doing what is at this example. I get the same error when I try to do echoargs of the connection info.
This is my powershell code I am testing at the command line since it hangs forever running the program:
sqlplus user/pw#RRRPRD.company.net:1521/RRRPRDC #"C:\Users\me\Documents\2021\temp endToEnd\short.sql"
This is using powershell 5.1. Any ideas? I see here string header, but since I am following the example that was accepted in the link for sqlplus above, it's unclear to me what's wrong with it.
Replace
#"C:\Users\me\Documents\2021\temp endToEnd\short.sql"
with any of the following:
`#"C:\Users\me\Documents\2021\temp endToEnd\short.sql"
"#C:\Users\me\Documents\2021\temp endToEnd\short.sql"
'#C:\Users\me\Documents\2021\temp endToEnd\short.sql'
Note: Using a verbatim (single-quoted) string ('...') is arguably the best choice here, given that the path contains no variable references; if it did, a expandable (double-quoted) string ("...") would be equired.
All variations end up passing the following string verbatim to sqlplus, which I presume is your intent:
#C:\Users\me\Documents\2021\temp endToEnd\short.sql
Presumably, you're trying to pass # as a verbatim part of an argument to sqlplus - a common convention among CLIs is to use #<file-path> to request that argument data be taken from a file rather than using the argument value itself.
However, unlike in other shells, # is a metacharacter in PowerShell that serves a variety of purposes.
Thus, a # that should be a verbatim character at the start of an argument must either be escaped (with `) or part of a quoted string, as shown above. See the conceptual about_Special_Characters help topic.
If an unescaped argument-initial # is followed by " or ', PowerShell thinks you're trying to create a here-string, which has special, multi-line syntax requirements; the error message indicates that they're not met.

How remove the first dash in a String with powershell script?

I want to remove the first dash of this string XXXXX-080-YYYYT in order to get a string that looks like XXXXX080-YYYYT with Powershell. No matter how long the word is, my goal is to remove the first dash. Please, can you tell me how to remove this dash from my string? . Thanks in advance.
$string= "XXXXX-080-YYYYT"
$string.Remove($string.IndexOf("-"),1)

Using variable which contains $ as password

I'm trying to deploy something through Octopus V4 and in my project variables, I got a password in which I have the special character $.
Assigning this Octo variable to a PowerShell variable will transform the string because PowerShell surely thinks that there is a variable in it. For instance, if I've got this:
azerty$qwerty
I'll end up with this:
azertyerty
So when it comes to start the deployed service with the appropriate credentials, it won't work. Just for the record: before starting the service, I'm creating it with the New-Service command in the deployment script of the project.
I read here and there that I need to use single quotes instead of double quotes to make it work but here my hands are tied since I'm just getting the variable from Octopus doing that:
$mypassword = $OctopusParameters["password"]
Any clue about how to keep the full string, $ included?
Please see About Quoting Rules as this may help.
When you enclose a string in single-quotation marks (a single-quoted string), the string is passed to the command exactly as you type it. No substitution is performed. When you enclose a string in double quotation marks (a double-quoted string), variable names that are preceded by a dollar sign ($) are replaced with the variable's value before the string is passed to the command for processing.
See below for an example of this behavior:
PS> $for = "my string"
PS> "test$for"
testmy string
PS> 'test$for'
test$for
Octopus may have its own way of dealing with this. I would try using double single quotes around the string and see if that helps, like ''my$string''.
I did also read in a forum that someone had success using the following cmdlet for password:
Set-OctopusVariable -Name 'password' -Value 'password123$'
This might be a silly question, but have you tried this already and it didn't work?
If you are using Octopus with the syntax:
$mypassword = $OctopusParameters["password"]
Octopus will not do any replacement of the value set in the Octopus parameter. Your foreseen issue will only appear if you are setting the password in double quotes inside Powershell directly, as in:
$mypassword = "azerty$qwerty"
And if you are doing this in Powershell, the correct way to set it will be to escape the $ with the tick (`) as in:
$mypassword = "azerty`$qwerty"

Add-Content to txt

I'm trying to make a GUI that will print the information from a textbox into a .txt in a way that I will try to explain as well as I can.
$TextBox_UsbName.text = "TestingTesting"
$Button_SetUsbName.Add_Click({ $Value_UsbName = $TextBox_UsbName.text; add-content -path $Value_NewScriptPath -value "$usbname = $Value_UsbName" })
After this is run I was hoping the text file would contain this:
$usbname = "TestingTesting"
I am still new to Powershell as well as coding in general and now I am really stuck I have tried a lot of different ways.
Any ideas and help would be much appreciated.
Edit: My result is
=
In Powershell double quoted string literals, string interpolation takes place each time an unescaped $ appears with a valid identifier characters after it. To introduce a literal $ that should not be parsed as part of an interpolated variable, you should escape it with a backtick, `.
Here is some quick string interpolation help:
How do I expand an expression in a string?
Windows PowerShell will expand a variable or an expression in a string.
Variables look like: $variable
Expressions look like: $(expression)
So, your "$usbname = $Value_UsbName" is interpreted by the engine as value of $usbname variable followded with = enclosed with spaces, and then a value of $Value_UsbName variable.
What you want to add is a literal $usbname substring and the value of $TextBox_UsbName.text expression.
So, either use
"`$usbname = $($TextBox_UsbName.text)"
Or just concatenate values (in a culture independent way):
$usbname + ' = ' + $TextBox_UsbName.text