I have a property file(env.properties) that contains below property name and value:
oracle.install.option=UPGRADE_DB
I have another shell script (test.sh) that runs source command and try to access the value of property oracle.install.option :
#!/bin/sh
source env.properties
echo "value is...... " $oracle.install.option
When I run the file .test.sh, I am unable to get the value of above property. Output:
env.properties: line 1: oracle.install.option=UPGRADE_DB: command not found
value is ......... .install.option
My expected output is UPGRADE_DB. Kindly assist me in getting this resolved.
This properties file is not a shell file, and dots are not allowed in environment variable names (read here)
So your hack could have worked if the properties had no dot in them, but not here.
So if you want to display it in your shell, you have another good alternative: parse the properties file using awk
awk -F= '{if ($1=="oracle.install.option") print "value is......",$2}' env.properties
Related
I would like to pass to a given Ruby script, a file as parameter. This file contains just a number (ID).
The command to run the Ruby scripts looks something like:
test export 123456 -o ./path/to/export -x
The number 123456 rappresents the parameter that i want to pass via txt/dat file from GitLab.
I tried:
test export "$(< /home/file.dat)" -o ./path/to/export -x
And also:
test export "`cat file.dat`" -o ./path/to/export -x
But i always get the same error:
cat: file.dat: No such file or directory
The very interesting point is that if i run cat before the other command, the content of the file is there (so the file is found). If i run it "nested" inside the Ruby command, it won't be found.
Any ideas how can i solve this?
Thank you very much
I'm not sure if this is what you're looking for, but you could pass the name of the file via command line and read the content of the file within the ruby script:
id = nil
# ARGV holds all the parameters passed to the script
File.readlines(ARGV[0]).each do |line|
id = line # id here will be set to the value contained in the file you passed a parameter
end
NOTE: I am a noob at bash scripts and the awk command - please excuse any dumb mistakes I make.
I am unable to substitute shell variables into my awk pattern. I am trying to scan through a file, find the first occurence of a specific string in the file, and print each line that succeed it in order until it hits an empty string/line.
I don't know the string I am searching for in advance, and I would like to substitute in that variable.
When I run this with the string directly specified (e.g "< main>:"), it works perfectly. I've already searched on how awk patterns work, and how to substitute in variables. I've tried using the -v flag for awk, directly using the shell variable - nothing works.
funcName="<${2}>:"
awk=`awk -v FN="$funcName" '/FN/,/^$/' "$ofile"`
rfile=search.txt
echo -e "$awk" > "$rfile"
The error is just that nothing prints. I want to print all the lines between my desired string and the next empty line.
Could you please try following, haven't tested it because no clear samples but should work.
funcName="<${2}>:"
awk_result=$(awk -v FN="$funcName" 'index($0,FN){found=1} found; /^$/{found=""}' "$ofile")
rfile=search.txt
echo -e "$awk_result" > "$rfile"
Things fixed in OP's attempt:
NEVER keep same name of a variable as a binary's name or on a keyword's name so changed awk variable name to awk_result.
Use of backticks is depreciated now, so always wrap your variable for having values in var=$(......your commands....) fixed it for awk_result variable.
Now let us talk about awk code fix, I have used index method which checks if value of variable FN is present in a line then make a FLAG(a variable TRUE) and make it false till line is empty as per OP's ask.
I have a parameter file(parameter.txt) which contain like below:
SASH=/home/ec2-user/installers
installer=/home/hadoop/path1
And My shell script(temp_pull.sh) is like below:
EPATH=`cat $1|grep 'SASH' -w| cut -d'=' -f2`
echo $EPATH
${EPATH}/data-integration/kitchen.sh -file="$KJBPATH/hadoop/temp/maxtem/temp_pull.kjb"
When I run my temp_pull.sh like below:
./temp_pull.sh parameter.txt
$EPATH gives me correct path, but 3rd line of code takes only partial path.
Error code pasted below:
/home/ec2-user/installers-->out put of 2nd line
/data-integration/kitchen.sh: No such file or directory**2-user/installer** -->out put of 3rd line
There is no need to manually parse the values of the file, because it already contains data in the format variables are defined: var=value.
Hence, if the file is safe enough, you can source the file so that SASH value will be available just by saying $SASH.
Then, you can use the following:
source "$1" # source the file given as first parameter
"$SASH"/data-integration/kitchen.sh -file="$KJBPATH/hadoop/temp/maxtem/temp_pull.kjb"
The problem is file which we were using was copied from windows to UNIX.So delimiter issue are the root cause.
By using dos2unix paramfile.txt we are able to fix the isue.
command:
dos2unix paramfile.txt
This will convert all the delemeter of windows to unix format.
I have a file called config.properties and I would like to read the value of a field from this file using shell script.
This particular file is available in path /u/application/run/config.properties.
Contents of this file :
resource=/Services
Environment=DEV.
I would like to read the value of the variable "Environment" which is DEV and assign it to a variable.
How can this be done ?
If that is literally the files contents and you can count on that format of contents being consistent and don't need to worry about shell metacharacters (like *, or [, etc.) in the values then you should be able to just source /u/application/run/config.properties and then use $Environment.
i know it is very basic question but im total new in shell scripting
i a txt file called 'berkay' and content of it is like
03:05:16 debug blablabla1
03:05:18 error blablablablabla2
05:42:14 degub blabblablablabal
06:21:24 debug balbalbal1
I want to print the lines whose second column is error so the output will be
03:05:18 error blablablablabla2
I am thinking about something like " if nawk { $2}" but i need help.
With this for example:
$ awk '$2=="error"' file
03:05:18 error blablablablabla2
Why is this working? Because when the condition is true, awk automatically performs its default behaviour: {print $0}. So there is no need to explicitly write it.