Page 1 of 1

RegEx find and replace (on contents) script example?

PostPosted: Tue Apr 12, 2022 10:39 am
by luhmann
I'm trying to set up a routine to do the following, and would like some help.

I have a folder of MD (markdown) files for Logseq and I would like to add some metadata to them. It seems I can match files which have the contents:

tag:: contact, ... (Ignore rest of line)...

but then I would like to add a line below that to all the matching files so that it looks like this:

tag:: contact, ... (Ignore rest of line)...
icon:: [human emoji]

As best I can tell I should probably run a script on the matching items. There are choices for shortcuts, applescript, java script, shell scripts, etc. I don't really care which, but would love to have a working example of a script that does Regex search and replace which I could modify for my own needs. I'm pretty handy with RegEx but terrible at the scripting part.

thanks!

Re: RegEx find and replace (on contents) script example?

PostPosted: Wed Apr 13, 2022 11:21 am
by Mr_Noodle
That's a bit outside of the normal support I can give but maybe someone else here has something handy. For a shellscript, you can look into either awk or sed to do the replacement.