Introduction
This solution is divided into multiple answers due to the 32KB size limitation for Ask Ubuntu (AU) answers.
This first section provides the user guide with screen shots and field explanations.
The next section provides the bash scripts that gets the job done.
Overview
All Ask Ubuntu (AU) answers are stored in HTML (Hypertext Markup Language) format. There is a high degree of confidence this application will work on all Stack Exchange (SE) sites but it has only been tested with AU.
The application will:
- Extract question title
- Extract question upvotes
- Extract answer upvotes
- Extract SE code matching first three lines of linked file name containing code
- Run
diff
command between SE code and local code displaying results in gedit
.
- Display progress bars
- Easy to use GUI with no terminal requirements
- No installation other than copying bash script
- Comes with sample data to existing files on disk (Ubuntu 16.04) and existing answers.
Sample Main Window

This demo screen had to be fast paced and frame reduced to fit within 2MB file limit. It shows the default data created when the script is first run. Here’s what’s happening:
- Select the second entry
- Click on the
Update
button
wget
downloads the question and answer from Stack Exchange a progress bar is briefly diplayed.
- The question and answer are analyzed and a progress bar is displayed for about 3 seconds.
- The
diff
command compared the local code ~/.bashrc
to the answer on Stack Exchange and gedit
was used to display the differences.
Here’s what was missed after the animation ended:

gedit
is used to display the differences between your local code ~/.bashrc
and the stack exchange answer.

After closing gedit
the main screen reappears and now the Question up-votes, Answer up-votes and Question title fields are populated.
Let’s drill down by clicking the View
button

Here you can see all the fields for an entry that don’t fit on the main screen. You can copy to the clipbaord the stack exchange website address which you could then paste into your browser. You can see the last modified date of the code file stored on your system.
The Status field could contain:
Update
- A new entry was added or an existing entry was changed. The Update button must be clicked to clear all fields tagged as update and set with real values from Stack Exchange.
Bad file
- The file name specified no longer exists.
Empty file
- The file name specified has zero bytes.
3 lines not found
- The first three lines of the specified file (blank lines are skipped) were not found in the Stack Exchange answer. Either the wrong file name was entered or the wrong Stack Exchange answer was provided or the files have been changed such that the first three lines no longer match.
Bad Answer
- The website address does not exist.
Answer < 1K
- The website address exists but the answer is less than 1 KB in size.
Different
- The local code file and the Stack Exchange Answer have differences.
Matches
- The local code file matches the Stack Exchange Answer answer.
Diff parameter Error
- The parameters used to call the diff
command contain one or more errors. Use man diff
to review valid options.
Project Scope
The primary purpose is to find out which answers have been modified by others and to roll those changes into local code files. The other purpose is to figure out which answers in Stack Exchange need to be updated after coding changing have occurred locally. Lastly “hot” answers can be tracked with tallies of answer votes.
No SQL database should be used. Only out-of-the-box-bash files must be used. The application must use yad
as the GUI user interface. Zenity
is too limited as it cannot display original values in forms, cannot hide columns when database is too wide and does not allow adding buttons to control program flow.
Explaining the sample main window shown above it displays scrollable entries containing:
- Radio button to select an entry
- The local file name containing code
- Answer Up-votes (which your posted code and written answer are garnering)
- Question Up-Votes (to show global interest in this SE question)
- Question Title
A summary of main window buttons are:
View
- view the selected entry.
Insert before
- insert a new entry before the selected entry.
Edit
- edit the selected entry.
Delete
- delete the select entry (confirmation is required).
Update
- download the answer from Stack Exchange and analyze it.
Cancel ALL
- Cancel all changes (confirmation required if changes have been made). Escape key or X on Window has same effect.
Save
- Save changes to disk.
The View
and Delete
buttons pop up a the same window as shown above.
The Insert before
and Edit
buttons pop up similar window but some fields are non-input and initialized with “Update”. This indicates the Update
button on the main window needs to be clicked to retrieve data from Stack Exchange later. The non-input fields are: File Date, Status, Answer Up-votes, Question Up-votes and Title.
June 2017 Updates
The code has been revised to sort array entries by Question Title + local file name when changes are saved. There is no longer any need to manually insert records in sequential order.
You can now update all
by clicking the update
button without selecting a specific records. When updating all file comparisons are rolled into a single file and presented by gedit
when complete. Answers with identical source code are not presented in dialog boxes interrupting the flow but put as status lines in the diff
file.
Accelerator keys are provided for buttons. Hold down Alt and then tap the first letter of the button you want to select.
sed
was taking 3 seconds to change HTML to text which was too long. It was replaced with built in bash
search & replace and time is now one second or less.
Unfortunately these code changes are 2,000 characters too long for Ask Ubuntu posting so please leave a comment if you would like a copy of the code and I'll find some place to post it for you.