Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have Linux machine red-hat 5.1 and I ask the following question

my target is to create new output_file.txt file from answer_file.txt according to data_file.txt

as we see here I run first the data_file.txt and export all parameters from the file then I try to print all answer_file.txt in to new file output_file.txt

so I will get this file with the new parameters from data_file.txt but I not success -:(

please advice how to export the parameters from data_file.txt in to answer_file.txt and then create new file with the correct values?

remark - I work with bash and I not want to use sed or awk for this task , and I not want to change the content of the original data_file.txt or answer_file.txt ( I need the simple way from bash shell to do the Job )

 [root@test1a /var/tmp]# more data_file.txt 
 arg1=a
 arg2=b
 arg3=c


 [root@test1a /var/tmp]# more answer_file.txt
 param1=$arg1
 param2=$arg2
 param3=$arg3



 [root@test1a /var/tmp]#  . ./data_file.txt 
 [root@test1a /var/tmp]# export arg1 arg2 arg3
 [root@test1a /var/tmp]#  cat `  . ./answer_file.txt  `  >/var/tmp/output_file.txt
 -bash: ./answer_file.txt: line 4: unexpected EOF while looking for matching `''
 -bash: ./answer_file.txt: line 5: syntax error: unexpected end of file






 ( my target is to get: Example of expected results from output_file.txt )

    more answer_file.txt  
    param1=a  
    param2=b  
    param3=c
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You need to run eval on each line in the file. Try this:

$ cat data_file.txt
arg1=a
arg2=b
arg3=c

$ cat answer_file.txt
param1=$arg1
param2=$arg2
param3=$arg3

$ . data_file.txt

$ eval "echo \"$(cat answer_file.txt)\""
param1=a
param2=b
param3=c

# alternative, shorter command
$ eval "echo \"$(<answer_file.txt)\""
param1=a
param2=b
param3=c
share|improve this answer
add comment

Sorry I didn't flesh this out more fully, I'm a bit tired (community, feel free to edit this and step in). Hopefully this will get you started with what you need:

$ cat data.txt
arg1=a
arg2=b
arg3=c
export arg1 arg2 arg3
$ cat answer.txt
echo param1=$arg1
param2=$arg2
param3=$arg3
$ eval `cat data.txt`;eval `cat answer.txt`
param1=a param2=b param3=c
share|improve this answer
    
-1 for adding an echo into the OP's answer file. –  dogbane May 1 '12 at 7:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.