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
1 Answer
The name of the current file is $ARGV
perl -pi -e 's/((?<=text": ")\S*(?="))/$ARGV/g' PATH-TO-FILE