RegEx find and replace (on contents) script example?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

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!
luhmann
 
Posts: 2
Joined: Fri Sep 08, 2017 12:28 am

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.
Mr_Noodle
Site Admin
 
Posts: 11867
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support