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

Reminder : Submit the commands themselves, not the output of the commands! Backg

ID: 639107 • Letter: R

Question

Reminder: Submit the commands themselves, not the output of the commands!

Background

In this assignment, in addition to the commands covered in the previous homework, we work with filters and commands such as grep and introduce sed and tr.

Part I. This part uses polls.csv from Assignment 2. **NOTE** Please use /ftproot/okeefe/215/polls.csv instead of your own polls.csv. Copy the new file to your assignment 3 sub directory before using it.(2 points each)

Show a list of all the polling organizations.

Count the number of unique polling organizations.

Part II: The Dictionary and Regular Expressions

The answers to these questions require using the command grep, in some cases wc, and the dictionary file (/usr/local/tmp/Words). The dictionary is case sensitive; keep this in mind when writing your grep commands. Also, for the purposes of these questions, only a, e, i, o and u are vowels (not y), and a consonant is any character that is not a vowel (including punctuation).

First, take a look at the contents of (/usr/local/tmp/Words). Note that each word has two entries. In normal and reverse order. In addition, the first letter of each word is upper case.

Using tr, convert all upper case letters to lower case. (1 points)

Using sed, remove the reversed copy of each word. [hint] Each word is followed by it's reverse on subsequent lines. Save the output of this command as a file named "words" in your home dir for use with the remaining questions. (3 points)

Count the number of five letter words in the dictionary. (1 points)

Count the number of 7 letter words in the dictionary that start with the letter "a" . (2 points)

Output all the words in the dictionary [$HOME/words] that have exactly six consonants (non-vowels) in a row. (4 points)

Explanation / Answer

While read Polling_Organization

Do

                Something with “$Polling_Organization”

Done

#to print list of Polling Organization ($1 is the column number in file)

Awk –F, ‘{OFS=”,”;print $1}’ ftproot/okeefe/215/polls.csv > Polling_Organization.csv

# to count unique polling organizatios

Awk –F ‘,’ {print $1}’ ftproot/okeefe/215/polls.csv | sort | uniq –c

# this would count the unique occurrences in the 1st field and prints the result

#You can also do this using wc command as follows

cut -f 1 ftproot/okeefe/215/polls.csv | sort | uniq | wc -l

# upper case to lower case

# general form $ tr '[:upper:]' '[:lower:]' < input.txt > output.txt

$ tr '[:upper:]' '[:lower:]' < usr/local/tmp/Words.txt > usr/local/tmp/Words.txt

# Count the number of five letter words in the dictionary.

xargs -n1 < dictionary.txt | grep -c ^.....$w

# Count the number of 7 letter words in the dictionary that start with the letter "a" .

$ cat dictionary.txt | grep –c ^a ^…….$w

# Output all the words in the dictionary [$HOME/words] that have exactly six consonants (non-vowels) in a row.

$ cat dictionary.txt | grep "[a-df-hj-np-tv-xz]{6}" $w