AWK print AWK command

awk '{print "awk '{sub(/pdb_00/,"pdb_"$0"_00"); print}' pdb_"$0"_00.namd > tempo"; print "mv tempo pdb_"$0"_00.namd"}' datA2.dat > copy_script2.bash 

This works when trying to print 'sed etc. etc' but if I switch to using AWK to print a set of AWK commands it doesn't work...

e.g. this WORKS:

awk '{print "sed 's/pdb_00/'pdb_"$0"_00'/g' pdb_"$0"_00.namd > tempo"; print "mv tempo pdb_"$0"_00.namd"}' dat2.dat > copy_script2.bash

Error is

line 3: syntax error at line 4: `(' unexpected

Try this:

awk '{print "awk \47{sub(/pdb_00/,"pdb_"$0"_00"); print}\47 pdb_"$0"_00.namd > tempo"; print "mv tempo pdb_"$0"_00.namd"}' datA2.dat > copy_script2.bash

You need to substitute the embedded single quotes with their octal representation.

It doesn't work.

Or maybe could I ask, is there a way to get sed to only substitute once (first time) instead of doing it globally?

"It doesn't work"? Could you be more specific (see How to Ask Questions the Smart Way)?

Just remove the trailing g from the sed script.