Input
editThe raw content of User:JVbot/WFB Flags is split into two files using sed.
articles.txt
editThis file is comprised of the first column of the table and looks like:
[[CIA World Fact Book, 2004/Afghanistan]] [[CIA World Fact Book, 2004/Akrotiri]] [[CIA World Fact Book, 2004/Albania]] [[CIA World Fact Book, 2004/Algeria]] [[CIA World Fact Book, 2004/American Samoa]] [[CIA World Fact Book, 2004/Andorra]] [[CIA World Fact Book, 2004/Angola]] [[CIA World Fact Book, 2004/Anguilla]] [[CIA World Fact Book, 2004/Antigua and Barbuda]] [[CIA World Fact Book, 2004/Argentina]] [[CIA World Fact Book, 2004/Armenia]] [[CIA World Fact Book, 2004/Aruba]]
params.txt
editThis file is comprised of the second two columns of the table, with the first converted to a regular expression in order to handle the different ways the images have been specified in the articles:
\[\[Image:WFB( |_)Flag( |_)of( |_)Afghanistan.png\]\] [[Image:Flag of Afghanistan (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Akrotiri.png\]\] [[Image:Flag of the United Kingdom (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Albania.PNG]] [[Image:Flag of Albania (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Algeria.PNG]] [[Image:Flag of Algeria (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)American( |_)Samoa.PNG]] [[Image:Flag of American Samoa (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Andorra.PNG]] [[Image:Flag of Andorra (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Angola.PNG]] [[Image:Flag of Angola (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Anguilla.PNG]] [[Image:Flag of Anguilla (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Antigua( |_)and( |_)Barbuda.PNG]] [[Image:Flag of Antigua and Barbuda (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Argentina.PNG]] [[Image:Flag of Argentina (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Armenia.PNG]] [[Image:Flag of Armenia (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Aruba.PNG]] [[Image:Flag of Aruba (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Ashmore( |_)and( |_)Cartier( |_)Islands.PNG]] [[Image:Flag of Australia (islands) (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Australia.PNG]] [[Image:Flag of Australia (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Austria.PNG]] [[Image:Flag of Austria (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Azerbaijan.PNG]] [[Image:Flag of Azerbaijan (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Bahamas,( |_)The.png\]\] [[Image:Flag of the Bahamas (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Bahrain.png\]\] [[Image:Flag of Bahrain (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Baker( |_)Island.png\]\] [[Image:Flag of the United States (WFB 2004).gif|200x54px]] \[\[Image:WFB( |_)Flag( |_)of( |_)Bangladesh.png\]\] [[Image:Flag of Bangladesh (WFB 2004).gif|200x54px]]
Command
edit$ (IFS=' ' && python replace.py -regex -file:articles.txt $(cat params.txt) )
Note: setting the IFS to a new line character tells bash to parse params.txt as one argument per line, irrespective of spaces on the line.
Result
editA test run has the following output:
Checked for running processes. 1 processes currently running, including the current process. Getting 50 pages from wikisource:en... >>> CIA World Fact Book, 2004/Afghanistan <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of Afghanistan.png]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Afghanistan (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/Akrotiri <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of United Kingdom.png]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of the United Kingdom (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/Albania <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB_Flag_of_Albania.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Albania (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/Algeria <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB_Flag_of_Algeria.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Algeria (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/American Samoa <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB_Flag_of_American_Samoa.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of American Samoa (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/Andorra <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of Andorra.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Andorra (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/Angola <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of Angola.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Angola (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/Anguilla <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of Anguilla.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Anguilla (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/Antigua and Barbuda <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of Antigua and Barbuda.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Antigua and Barbuda (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) M Do you want to accept these changes? ([y]es, [N]o, [a]ll) N >>> CIA World Fact Book, 2004/Argentina <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of Argentina.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Argentina (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) >>> CIA World Fact Book, 2004/Armenia <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of Armenia.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Armenia (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll) >>> CIA World Fact Book, 2004/Aruba <<< - |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:WFB Flag of Aruba.PNG]] + |width="24%" align="center" bgcolor="#CCCCCC"|[[Image:Flag of Aruba (WFB 2004).gif|200x54px]] Do you want to accept these changes? ([y]es, [N]o, [a]ll)