venhart
1
Hi,
Please could someone advise the issue i have with my awk command ?
my command is :
export NUM_SCENARIOS=`awk -F= '!/^#/ && /NUM_SCENARIOS/{print $2}' /home/environment.properties`
when I echo $NUM_SCENARIOS
this comes back with :
100 10
The issue I have is, there is another variable called "REP_NUM_SCENARIOS" and this value is 10.
I just need the first varible "NUM_SCENARIOS" which the value is 100.
What do i need to amend with my awk command show me just the value of "NUM_SCENARIOS" ?
thankyou
whats the contents of environment.properties?
--ahamed
can you post the lines of REP_NUM_S.... and NUM_SCENARIOS lines
yazu
4
Try:
export NUM_SCENARIOS=`awk -F= '!/^#/ && /([^_]|^)NUM_SCENARIOS/{print $2}' home/environment.properties`
venhart
5
NUM_SCENARIOS=100
REP_NUM_SCENARIOS=10
#using sed
export NUM_SCENARIOS=`sed -n 's/^NUM_SCENARIOS=\([0-9]*\)/\1/gp' file`
#using awk
export NUM_SCENARIOS=`awk -F= '/^NUM_SCENARIOS/ {print $2}' file`
--ahamed
Do you get the correct output with?
awk -F"[= ]" '!/^#/ && /NUM_SCENARIOS/{print $2}' /home/environment.properties
awk -F= '!/^#/ && $1~/^NUM_SCENARIOS$/{print $2}' /home/environment.properties
---------- Post updated at 04:27 PM ---------- Previous update was at 04:26 PM ----------
$ nawk -F= '!/^#/ && $1~/^NUM_SCENARIOS$/{print $2}' test
100
$ cat test
NUM_SCENARIOS=100
REP_NUM_SCENARIOS=10
venhart
9
Thank you this works fine :
export NUM_SCENARIOS=`awk -F= '!/^#/ && /([^_]|^)NUM_SCENARIOS/{print $2}' home/environment.properties`
now I have a environment.properties.template
with blank values :
NUM_SCENARIOS=
REP_NUM_SCENARIOS=
how can i populate the blank values from the above $NUM_SCENARIOS awk command ?
$ source my_test
$ echo $NUM_SCENARIOS
100
$ echo $REP_NUM_SCENARIOS
10
$ cat my_test
NUM_SCENARIOS=100
REP_NUM_SCENARIOS=10