For a migration process, I need to do some replacement in my bash script.
So in my .txt files, I have these references for example:
[[File:My Image.png|400px|thumb|center|My Image]]
[[File:My Image.png|400px|thumb|center]]
[[File:My Image.png|400px|thumb]]
[[File:My Image.png|400px]]
[[File:My Image.png]]
What I need to do is to replace all these occurrences with this line (only - so no more size, description, or other informations):
[[File:My Image.png]]
So, I tried to do a is to build a PCRE regex to extract all images names with:
/File:(.*\..{3})/g
I've built this final command to find all occurrences in my .txt files and extract image name with my regex:
find . -name "*.txt" | xargs perl -i -p -e 's/File:(.*\..{3})/$1/g'
But, I've encountered some problems as:
- An error:
xargs: unterminated quote
- And finally I don't know how to use extracted image name to replace all occurrences (complete lines)
PS: I'm on MacOS system and use bash v4
File:x|y
(without the preceding[[
). – haukex Apr 04 '18 at 11:00[[
or ending]]
, so probably they do not make a difference for given input... – Sundeep Apr 04 '18 at 11:12