I am struggling with awk substitution, for some reason the following code does not substitute anything, it just prints the output unaltered. Can anyone see what I am missing here? Any help would be very much appreachiated! (PS! The $DOCPATH and $SITEPATH are shell variables, they work perfectly fine in my awk setup).
awk -v docpath="$DOCPATH" -v sitepath="$SITEPATH" '{ sub( /docpath/, sitepath ) } { print }'
Saying:
sub( /docpath/, sitepath )
causes awk
to replace the pattern docpath
, not the variable docpath
.
You need to say:
awk -v docpath="$DOCPATH" -v sitepath="$SITEPATH" '{sub(docpath, sitepath)}1' filename
Couldn't help to write this in sed:
sed 's/'"$DOCPATH"'/'"$SITEPATH"'/' input
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With