Here’s another little Bash script I whipped up. If you’re hoping to take the GRE, you’ll know that it includes two essays or analytical writing tasks – one ‘argument’ task and one ‘issue’ task. ETS, the maker of the GRE, lists the entire pool of topics on their website. This script picks a random essay topic from the pool of GRE argument and issue topics.
First I saved the two webpages and extracted the content from them. I converted the resultant files into Markdown with judicious use of regex substitutions. (I could have used pandoc
, but that’s just occurring to me now as I write this…)
Normally, you can use shuf
to get a random subset of lines from a file. But here, all the topics have multiple lines/paragraphs. I replaced the horizontal rules between topics with ---
in the resultant Markdown, so I decided to split each topic into its own file using:
$ awk '{print $0 ""> "issue" NR}' RS='---' ../issue\ topics.md
$ awk '{print $0 ""> "argument" NR}' RS='---' ../argument\ topics.md
(These two commands are in their own respective directories, for clarity.)
So now, we can use shuf
to get a random file from each directory!
I wrote a quick script that picks an essay prompt for each. View it here.
Let me explain a few lines.
datestr=$(date '+%Y-%m-%d')
filename=$datestr"_AWA_topics.md"
touch $filename
This creates a file with today’s date, e.g. 2019_12_28_AWA_topics.md
.
argpromptfile=$(ls /home/tesserakt/College/Fall_2019/GRE/arg_pool | shuf -n 1)
issuepromptfile=$(ls /home/tesserakt/College/Fall_2019/GRE/issue_pool | shuf -n 1)
This lists the files in each directory – remember, each file contains a single topic – and run shuf
on those, to get one topic for each. The chosen filename is stored in the variable.
-
After that, we
cat
the files and append them to our initial file. (>>
appends, whereas>
overwrites.)
sed ':a;N;$!ba;s/\n\n\n/\n\n/g'
$filename > $filename.tmp
mv $filename.tmp $filename
cat $filename
The sed
looks cryptic – basically, we replace triple newlines \n\n\n
with double newlines \n\n
. This preserves spacing between paragraphs while removing excess whitepace. (Check out the link below for a more detailed explanation of this command.)
Finally, we view the file with our two topics. Et voilà!
References: