Ok, so this is stupid simple, and I know I am going to feel like an idiot when I get help.
I am altering a HTML report that has contraband in it so that the links to said contraband and the images are not shown.
The link/img pairs are in the form of :
<a href="files\Image\imgcache.0_embedded_47.jpg" title=""><img src="thumbnails\imgcache.0_embedded_47_thumb.jpg" style="width:100%; height=100%"></a>
All the replacements I need to do start with "files" in the link, and "thumbnails" in the image tags. Everything after that is variable.
The sed command I am using is :
sed 's#\<a href=\"files*\>\<img src=\"thumbnails*\>#\<img src=redact.png\>#g' File\ System\ Extraction\ Report.html > altered.html
Any help would be appreciated, as I have spent way to long on this already.
Can you also post desired output for that sample data?
Yes, the desired output would take the original link and image tags and replace them with just :
<img src=redact.png>
sed uses regexes, not globs, which explains part of your difficulty.
files*
In shell globbing, * means "anything else". In regex, it means "zero or more of the previous". So files* would match files, filess, filesssssssssssssssss, but wouldn't match files\
The regex equivalent would be .*, where . is a special character mean "match anything". But I'd try something a little trickier, to match > so that part of the regex doesn't scan outside the tag it started in. [] let you specify a range to include or exclude. [A-Z] would match a single letter in A-Z range. [^A-Z] would match a single character not in the A-Z range. [^>] would match anything that's not an end-of-tag character.
So, [^>]* would match zero or more non-> characters, swallowing up the rest of the tag and stopping right before >.
This works on the HTML you posted:
sed 's#<a href="files\\[^>]*><img src="thumbnails\\[^>]*></a>#<img src=redact.png>#g'
Worked perfectly. Thank you for the help, and the lesson. I thought sed used bash's rules. Learn something new everyday.
Look for 'POSIX regular expressions' to see exactly how sed and many other things match. BASH globbing is pretty limited in comparison. PERL regexes are similar to POSIX ones but even more plush.