Automated craigslist job search with Perl and Bash

Most of my students are in the job market and after suggesting them websites where they could look for jobs, I took a peak at craigslist. I like craigslist; its a simple, bare-bones website with pure text. However, the search functionality is a bit awkward, and it is hard to find a good match between the candidate skills and a particular job posting. If you are seriously looking at every single “filtered” post, it may still take you over an hour to look for the best skill-to-job matches. So I created two scripts, one in Perl and the other one in Bash, that scavenge all the job postings for skill matches, and create a new webpage with all the appropriate positions and matched skills in a ready to click link. Data mining at its best!

There are some “limitations” of these scripts. First of all they were only tested in macOSX and Linux, however I am sure you can convert them quite easily to Windows. Secondly, I’ve focused all the craigslist searches around New England. You may add other craigslist locations quite easily by following the instructions on the perl script.

This automated job search requires two files: search_jobs.sh and craigslist.pl. Both can be found below, or at my github repository. To run the code place both files in the same directory, and edit the search_jobs.sh, shown below, with a text editor (after emacs, my second favorite text editor is TextWrangler). In this file modify the appropriate keywords that are being assigned to the variable SEARCH_SKILLS. Currently the search skills are the standard qualifications for an engineering graduate.

This script runs with the following command line:

chmod u=+rwx search_jobs.sh
./search_jobs.sh

Running the scripts on a macosx terminal window.

After it is done executing it will create two files engineering.html and finance.html, where the candidate can see his best job matches.

Two html files are created with the best job matches

Generated HTML file with the best job matches


Below is the Perl script that parses the craigslist job postings.


File related Linux bash snippets

Here are some of extremely useful Linux bash snippets I use all the time to parse experimental data from my simulations.


How to extract the top (insert number here) lines from a file
Consider a file named test-file.txt. You can extract the top 14 lines from that file using the following:


How to extract specific lines in a file using regular expressions.
Consider a file, named test-file.txt, with the following lines:
_N37_:0:_N262_:1:_N696_:0
_N37_:0:_N233_:0
_N37_:0:_N263_:0:_N694_:0
_N37_:1:_N113_:0

To extract the lines that have 5 elements we can type:

To extract the other lines, we can simply negate that regular expression:


How to search and replace text on a file

Where string1 is what you are searching for, string2 is what you want it to be replaced with and file.txt is the file you want to perform this operation on.


How to print a specific line number inside a file using a variable

Where $LINENBR is the number of the line you want to print.


How to append 2 files, column by column, keeping particular columns


How to transfer files across computers with ssh
The scp command copies files to a remote Linux system.

To copy files from a remote system to your local system:


How to remove a file extension


How to remove redundant lines inside a file
In the terminal type:


How to delete the last line of a file
In the terminal type:


How to count the number of lines in a file and write that number into another file
In the terminal type:

Alternatively you can also store the number of lines into a shell variable.


How to perform the same operation over several files
In a bash script type:

this will print out all filenames via an echo command, that will have the regular expression FAULTY*


How to write a loop inside a bash file


How to split a string inside a bash file


How to do input parameter error testing
The variable ${CIRCUIT} is the first command line argument (${1})


How to perform a particular operation on each line of a file


How to ensure that two files have the same number of lines

Where file1.txt and file2.txt are the filenames you wish to compare.


How to count the number of characters in file
In this particular example, the character I am counting is the 0.


How to replace characters in a file
This particular command will replace all “:” with the newline character.


How to delete all instances of a particular character from a file
This particular command will delete all “:” from the file longString.txt and it will write it on the file readableString.txt.

Read the rest of this entry »