Windows batch script to replace a string - windows

I have a txt file that looks like this:
file: config.txt
property name="java.nio.preferSelect" value="true"
property name="pico.rcp.platform.host" value="172.22.3.11"
property name="pico.rcp.platform.port" value="6790"
I want a windows batch script that will search for "pico.rcp.platform.host" string and change the IP value in that line regardless its value to the passed value in the command line. Like the following:
changeServerTo.bat "172.22.3.1" config.txt
the above script should make the file looks like this:
file: config.txt
property name="java.nio.preferSelect" value="true"
property name="pico.rcp.platform.host" value="172.22.3.1"
property name="pico.rcp.platform.port" value="6790"
and
changeServerTo.bat "172.22.100.221" config.txt
should make the file looks like this:
file: config.txt
property name="java.nio.preferSelect" value="true"
property name="pico.rcp.platform.host" value="172.22.100.221"
property name="pico.rcp.platform.port" value="6790"
and so on.
Your help is much appreciated.
Thanks in advance.

This script just rewrites the entire file and uses the parameter in the output
echo property name="java.nio.preferSelect" value="true" >config.txt
echo property name="pico.rcp.platform.host" value=%1 >>config.txt
echo property name="pico.rcp.platform.port" value="6790" >>config.txt

Related

Create a dynamic path inside a yaml file

I have a yml file that contains a path for data source. Something like this:
data_source: s3://bucket/file.csv
I want to change the job to grab only the file with yesterday appended to the title, for example:
file-2021-10-21.csv
so basically, something like this:
data_source: s3://bucket/file-{yesterday}.csv
How can i define it in the yaml file? thanks!
You can have something like below, where all files defined under 'files' variable
data_source: s3://bucket/file-
files:
- 2021-10-21.csv
- 2021-10-21.csv

Parametrize source folder directory or file path in JMeter

Is there any way to parameterize the CSV data file path or source directory path in JMeter?
There are at least 2 possibilities:
Via User Defined Variables like:
and then referring the variable in the CSV Data Set Config
Or via __P() function like:
the property value can be passed via -J command line argument or put into the user.properties file. See Overriding Properties Via The Command Line for more information.

Clear all property values in a properties file

I have a properties file which contains several name=value pairs. This properties file contains several secrets in value. My requirement is to delete the property value after reading the values using a shell script. The property file will also contain comments.
Properties file:
#docker image key
name=secret_value
#username
abc=bcd
#password
def=efg
The shell script should delete all values after reading the properties file like:
New Properties file :
#docker image key
name=
#username
abc=
#password
def=
How to achieve this?
In the script, after the properties file is read, add the below command:
sed -i 's/\=.*/=/' property_file_name

How to set an env variable's value as null

Sorry if it's a repeat question. I couldn't find the answer anywhere.
My java application expects a password through an environment variable.
My staging environment doesn't have any password setup. How can I send a null value to the java application through env variable?
export pass=
If I put the above ^ in my ~/.bash_rc file, it isn't working.
EDIT :
I'm using spring & hibernate and taking the value in the XML. Something like the below:
<bean id="myclass" class="mu.package.Myclass">
<constructor-arg index="0" value="${pass}"/>
</bean>
If I replace ${pass} with ${pass:#{null}} to handle null checks with spel, it always takes the null value because the value is not present as a property but as an env variable. Is it possible for ${pass:#{null}} to check both properties & env variable before assigning null value?
Make sure your configuration has defined a PropertyPlaceHolder element in the XML:
<context:property-placeholder />
Then you simply need to make sure that by setting up the system environment variable that it is named exactly the same as your XML configuration expects for it to be translated.

File locations in shell script property files

I have a property looks like below in property file and the properties are ready by "sourcing" in shell script.
MW_INSTALLER_11.6="/ade_autofs/scratch/test/installer/wls_generic.jar"
During sourcing, observing the below error and the variable is not read.
Where all other properties are read perfectly fine.
./upgrade.properties: line 45: MW_INSTALLER_11.6=/ade_autofs/scratch/test/installer/wls_generic.jar: No such file or directory
The file mentioned above is present specified path. Observing same issue with or without double quotes.
What is the right way to add the file location in property file?
Code around above specified property in property files
POST_UPGRADE_ANT_OPTIONS=
MW_INSTALLER_11.6="/ade_autofs/scratch/test/installer/wls_generic.jar"
NO_OF_RELEASES_TO_UPGRADE=1
Code around sourcing property file in shell script, here $1 represents property file
echo "Reading properties file $1" | tee -a $LOG_DRIVER_FILE
. ./$1
UPGRADE_PROPERTIES_FILE=$1
thanks In Advance, soman
I found the issue. Issue is due to the variable name contains "." [dot]
after changing from MW_INSTALLER_11.6="/ade_autofs/scratch/test/installer/wls_generic.jar"
to
MW_INSTALLER_11_6="/ade_autofs/scratch/test/installer/wls_generic.jar"
It worked fine.
Regards.

Resources