Replacing using sed with variables from another file?
Hi,,
I'm using a fortran script to output a file with a set of variables. I then need to replace a series of numbers (11111, 22222...) within a larger job with those created in the fortran. Originally I was using 'set' to define them eg: set line = '1600P2' set seq = '087' cat ${job} |\ sed -e s~11111~$line~g |\ sed -e s~22222~$seq~g >! ${outfile} which would do the trick but involves entering the file and changing line, seq, the .f90 code reads from command line and creates a collumated file (parametersfile) with these variables. I would like to be able to use awk to extract the correct collumn in this file and replace the variables in the main job for example: cat ${job} |\ ./.params |\ sed -e s~11111~|awk '{print $1}' parametersfile|~g |\ sed -e s~22222~|awk '{print $1}' parametersfile|~g >! ${outfile} Obviously this doesnt work so is there a way of doing this by changing the set preamble, changing the sed string or perhaps a different command altogether? Many thanks, Jon. |
Hi again,
It may be simpler if I refine my query… is it possible to create a temporary parameter that links to the value in another file? for example: set temp = /usr/dir/proj/filename or temp = awk ‘{print $1}’ filename so that: cat ${job} |\ sed -e s~11111~$temp~g > ${outfile} Otherwise is there a way of piping awk through sed to replace 11111 with the variable? J. |
This seems to do what you want
Code:
file t.t: |
Quote:
Hi Chris, That'll work but you still have to define t within the code, which is a pain if you've lots of variables changing in the file. I would like the script to find the value within the file so that when the file changes, I dont need to re-enter the script. Jon. |
Nearly there, I think. Re: Replacing using sed with variables from another file?
Hi folks,
just had a mini breakthrough if I: Code:
set infile1 = file but I cant as yet run many foreach strings like: Code:
Jon. |
Hi again folks,
managed to get it working by: Code:
Jon |
All times are GMT -5. The time now is 12:06 AM. |