Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Additional exercise: Login to ftp.fec.gov as an anonymous ftp user, and obtain t

ID: 3605993 • Letter: A

Question

Additional exercise: Login to ftp.fec.gov as an anonymous ftp user, and obtain the 2012 candidate file cn12.zip, located in the /FEC/2012 directory on the server. Extract the contents of the zip archive using the unzip utility. Look inside the cn.txt file and observe its data. The format of this file is described at http://www.fec.gov/finance/disclosure/metadata/DataDictionaryCandidateMaster.shtml. Use UNIX tools you already know to make one single command line (using pipes) that will answer the following question: How many candidates in the 2012 election had the family name Jones? Your answer must contain the command line and the number.

Explanation / Answer

The answer to the query is
cat cn.txt | cut -f2 -d| | grep -i jones | wc -l

1. Open your browser and launch the given URL - ftp://ftp.fec.gov/FEC/2012/
2. If there is a prompt for username - enter "anonymous" (without quotes)
3. Go to /FEC/2012 folder
4. Download cn.zip and extract the file
5. After extraction, you should find the cn.txt with the following contents.
H0AK00089|CRAWFORD, HARRY T JR|DEM|2010|AK|H|00|C|P|C00466698|4350 BUTTE CIR||ANCHORAGE|AK|99504
H0AK00097|COX, JOHN ROBERT|REP|2012|AK|H|00|C|N|C00525261|PO BOX 1092||ANCHOR POINT|AK|995561092
H0AL00016|BOZEMAN, MARTHA RENEE|UNK|2010|AL|H|07|O|C|C00464040|PO BOX 2512 ||BIRMINGHAM|AL|35201
H0AL01030|GOUNARES, PETER HUNTER|REP|2012|AL|H|01|C|C|C00459495|PO BOX 1010||ORANGE BEACH|AL|36561
H0AL02087|ROBY, MARTHA|REP|2012|AL|H|02|I|C|C00462143|3260 BANKHEAD AVENUE||MONTGOMERY|AL|36106
H0AL05049|CRAMER, ROBERT E "BUD" JR|DEM|2008|AL|H|05||C|C00239038|PO BOX 2621||HUNTSVILLE|AL|35804
H0AL05155|PHILLIP, LESTER S|REP|2010|AL|H|05|C|C|C00462481|124 BAY BERRY LANE||MADISON|AL|35758
H0AL05163|BROOKS, MO|REP|2012|AL|H|05|I|C|C00464149|7610 FOXFIRE DR.||HUNTSVILLE|AL|35802
.....


6. Now, for the answer to the given question, here is the command. Launch the terminal in your linux machine and go to the folder that contains the cn.txt file. Enter the following command and press enter.

cat cn.txt | cut -f2 -d| | grep -i jones | wc -l


Explanation -
a. "cat <file name>" - will print the contents of the specified file on the console
b. "cut -f<field no> -d<delimiter>" - this command is used to extract the text at the specified field position. The "-d" option is used to specify the field delimiter
c. "grep -i <search text>" - The Grep command is used to search for text with particular pattern
d. "wc -l" - the wc command can be used to count the number of lines

In Summary,
1. we use the "cat" command to print the contents of the cn.txt file to console. This output is directed to the subsequent command using the pipe (|).

2. The "cut" command is used to extract the candidate name that is specified in the 2nd column. Refer to http://classic.fec.gov/finance/disclosure/metadata/DataDictionaryCandidateMaster.shtml for the column description.
As the delimiter in the cn.txt file is the character (|), we need to specify it in the cut command
Important: As pipe (|) character is a reserved in unix shell, we need to escape it with "".

3. Next, we use the grep command to search for the specified text viz - "jones. The "-i" option is used for case insensitive search

4. Finally, the "wc -l" command is used to count the number of lines in the result.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote