After this discussion about using backtick code for filenames in markdown, I now need to go back through all my .md files and change *some.filename.php* to *`some.filename.php`* every time it happens.
I'm sure some sort of $1 and $2 arguments might work in sed or awk, but I have no idea how or which is best. Here's the criteria I'm up against:
- All filenames are in italics asterisks with an asterisk
*at the end:*some.filename.php* - A space might preceede the file name in asterisk italics or not:
*asterisk italics then some-filename.php* - All file names end with an extension, but not always
.php. They could end with.xmlor.cssor.whatthefork. - Some file names might have two periods
.in them, some might not.
Example of my text:
*Read through index.php*
*Notice the changes below:*
- *some.file.php*
- *and anotherphpfile.php*
- *don't miss this.four.word.file.amp*
- *backup.txt*
- *index2.html*
- *style3.css*
- *action.js*
*Look at XML in my-feed.xml*
What can I run against the .md file so every filename in the file contents will become wrapped in backticks like so:
*Read through `index.php`*
*Notice the changes below:*
- *`some.file.php`*
- *and `anotherphpfile.php`*
- *don't miss `this.four.word.file.amp`*
- *`backup.txt`*
- *`index2.html`*
- *`style3.css`*
- *`action.js`*
*Look at XML in `my-feed.xml`*
This might be what you want, using a sed that supports
-Eto enable EREs such as GNU or BSD sed:but be aware that Unix file names can contain
*s or white space, including newlines, as well as any other characters except/orNULin which case the above regexp would fail to match them, it'd only match file names that look like the ones in your example.This would accept file names containing all chars except
*and white space as there's no way given input of*and anotherphpfile.php*to tell ifandis part of the filename or not if file names can contain white space and it might match other strings you don't want to match in input in other contexts that you haven't shown us: