If the file's syntax is compatible with the shell's, you can simply use the source command, the lone dot:
With the example you have provided, this would assign "abc" to the variable hs, "def" to hs1, and "ghi" to hs2.
If that's not what you want, you could perhaps read in one line at a time, remove everything up through the first equals sign, and then assign the result to some variable.
This reads three lines and assigns anything after the first equals sign on each of those lines to the selected variable name; successively, var1, var2, and var3.
The use of eval is a rather advanced technique; I would advise against this if you can come up with a simpler solution.
hi era
i am able to retrieve a value from a file, but i dont know how to assign the retrieved value to a variable. the code i have is
#regressiontest.cfg
hs=abc
hs1=def
hs2=ghi
now i am retrieving the value from the above file
RetrieveCfgvalue()
{
CFG_VALUE=`grep "$2=" $CONFIG_FILE_NAME | cut -d"=" -f2`
CFG_VALUE=`echo $CFG_VALUE|sed -s "s/ *//g"`
CFG_VALUE=`echo $CFG_VALUE|sed -s "s/\"//g"`
if [ ! -z $CFG_VALUE ]
then
eval "$1=$CFG_VALUE"
fi
}
Your function looks like it already does this. After RetrieveCfgvalue hs hs you should have the value of hs in the variable hs, isn't that correct? Then if you also want to assign it to var1, you can say var1=$hs (or simply RetrieveCfgvalue var1 hs directly, if that was what you were planning anyway).
hi era
the proble occuring is i have
hs=lpdma520.dev.ipc.us.aexp.com
hs1=lpdma521.dev.ipc.us.aexp.com
hs2=lpdma522.dev.ipc.us.aexp.com
like this in the cfg file.
When i tried to retrieve the value by using the above function
i am getting "command not found"
can u please help
Shell script logic
Hi
I have 2 input files like with file 1 content as (file1)
"BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt
File 2 contents as fle(2)
"BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt
I want to get... (22 Replies)
Hi,
I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file.
File1 - file2 = file3
wc -l file1.txt
58112
wc -l file2.txt
55260
head -5 file1.txt
101214200123
101214700300
101250030067
101214100500... (10 Replies)
I am using aqua studio DB. I need to retrive the data from my database using uxin script in .csv format. i am using select query along with the joins. my o/p in the DB is of the below format.
Cycle IDCycle StatusRecord 98N-0000ACV23-3636FCliet Level (Af)Success1689393HF-J7879-09090RCliet Level... (1 Reply)
Hi Friends,
I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving...
File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Hello friends!!
I have a question regarding the use of ls in unix. I have a folder with files:
t1.txt
t2.txt
t3.txt
t4.txt
...
t10.txt
When I make an ls I always get:
t10.txt
t1.txt
t2.txt
t3.txt
..
t9.txt (2 Replies)
Hello Everybody,
I'm facing a weird problem with the awk command.
I try to retrieve in a variable the value returned by a simple ls command.
ls /export/home/tmp |tail -1 return a good value (the name of the .
But When I try to execute the same command in a remote server using ssh as... (2 Replies)
Dear friends,
please tell me how to get some required lines from a file and write to another file using AWK command.
i.e.,
if a file contains,
abcdefghigk
12345
lmnopqrstuv
678910
wxyz
please tell me how to get lines(line count is always 2 and it's contineous) mentioned in blue... (1 Reply)
I have shell script which reads files, stores its data into Oracle and then deletes tht file.
now i want to know creation date and time of deleted files.
can we do this? if yes then how? (4 Replies)
hi
i have following file.
where i m trying to retrive data on latest date.
let us say we are extracting data from this file for Jun 30 where date is highest date in log file.
here i want to take output in other file from first line of Jun 30 to the end of file
in short i want retrive... (5 Replies)