[SOLVED] Difficulty cleaning references to duplicated images in HTML code
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Difficulty cleaning references to duplicated images in HTML code
Hi,
I need to search and replace references to duplicated images in HTML code. There are several groups of duplicated images, which are visually the same, but with different filenames. I managed to find the duplicated files themselves, but now I need to clean the code too. I have a CSV file with each group of duplicated images organized:
Code:
Group ID,Duplicated image filename, Number of duplicates
0,13429.png,3
0,18064.png,3
0,25025.png,3
1,14136.png,4
1,17382.png,4
1,19243.png,4
1,25389.png,4
2,21560.png,2
2,5529.png,2
3,3523.png,2
3,4811.png,2
and so on...
The references to duplicated images are scattered throughout hundreds of HTML files. The task is to get the <img> tags that references duplicates pointing to just one unique image in each group. I'm wondering if some script magic could get it done easily.
HTML (before): different files, same visual appearance
Is there any way to delete the original files and remove the "result-" part in the new file's names, inside this same script? I'd like to replace the old files with the results.
awk '...{print >> ("result-" FILENAME) }...' duplicates.csv *.html
# Note: this assumes none of the original files had "result-" as a prefix.
for result in result-*.html ; do
mv "$result" "${result#result-}"
done
Brillhant. Thanks again for your help! Here's the complete code:
Code:
awk -F, 'NR==FNR {Ar[$1]=Ar[$1](Ar[$1]?"|":"")$2;
if (!Rr[$1])Rr[$1]=$2; next}
{for (i in Ar) gsub (Ar[i], Rr[i])}
{print >> ("result-" FILENAME) }
' dupes.csv *.xhtml
for result in result-*.xhtml ; do
mv "$result" "${result#result-}"
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.