how to substitute filepaths with sed or awk?

I am having the following problem. I am having a lot of files (test_1_01.hea, test_1_02.hea, etc) with the content:
project_directory /net/1/d_1/5/
tmp_directory /net/1/d_1/5/
material_directory /net/1/d_1/5/

And I have to substitute the filepaths with new counted ones where the test_1_01.hea file are.

I wanted to do it with this script, but it doesn't work, because awk has problems with the '/'. Does someone has an idea.

for i in d_*
do
    cd $i/5/
    folder=`pwd |awk '{print $1}'`
    awk '{ if (NR==14) {gsub($2, $folder); print} }' test_1_01.hea
    cd ../..
done

Thanks for any suggestions, Sam.

awk -v folder=$folder '{ if (NR==14) {gsub($2, folder); print} }' test_1_01.hea

See if that helps

I don't quite understand this. But if you want to substitute the 2nd field in the file "test_1_01.hea" by the present working directory, then try this:

awk "sub(\$2,\"$PWD\")" test_1_01.hea

PWD is a Bash shell environment variable that is analogous to the pwd builtin.

tyler_durden

ok, thanks. Mainly it works.

@jim mcnamara: It is substituting the old folder with the new one - but only in the output. not in the file.

@durden_tyler: Do you have also an idea how to substitute the folders only in line 14, 16, 17 and the rest is also printed into the *.hea-file?
Maybe I am having tomatoes on my eyes...

Thanks again

---------- Post updated at 09:28 AM ---------- Previous update was at 08:36 AM ----------

ok, forget about it. Works fine... Tomatoes. I am just telling you tomatoes...
Thanks a lot for your help.