Perl replace string inside file with the filename?

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

1 Answer

The name of the current file is $ARGV

perl -pi -e 's/((?<=text": ")\S*(?="))/$ARGV/g' PATH-TO-FILE 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like