I need to replace a string in a JSON file with the filename of that file. I successfully matched the string to be replaced using the regex below, but I can't figure out how to get the filename in there to replace the string with.
Note: This is a script used in a rule inside the Hazel app. The app tells me to refer to the file being processed in the script using '$1'. So how do I insert the filename for the file $1 in the find and replace function below?
perl -pi -e 's/((?<=text": ")\S*(?="))/FILENAME/g' PATH-TO-FILE
sed
:sed -i 's/TEXT_TO_CHANGE/FILENAME/g' path/to/file/FILENAME
will change all the strings TEXT_TO_CHANGE with FILENAME. Try before without-i
to see the effect.