Programming Excersises A

Programming Excersises A

Step 1

Write the command to download the text file with the following URL to

your computer with the filename “frost.txt”.

Here’s the URL: http://rwet.decontextualize.com/texts/frost.txt

curl http://rwet.decontextualize.com/texts/frost.txt > frost.txt

Step 1a

Verify step 1 by typing the following command:
$ cat <frost.txt
Screen Shot 2015-02-04 at 11.00.08 AM
Step 2
Write a command that displays the only the lines from frost.txt
that contain the string “And”.
grep And <frost.txt

Step 3

Using a pipe, write a command that extracts the second word from
each of the lines you displayed in Step 3.

grep And <frost.txt | cut -d” ” -f 2

Step 4

Add one more element to the pipe in step 3, so that the words are
displayed in alphabetical order.

grep And <frost.txt | cut -d” ” -f 2 | sort

Step 5

We didn’t talk about “fold” in class, but it’s a useful command for
word-wrapping text. Investigate the “fold” command with “man” (type “man fold”) and write a command below to word-wrap “frost.txt” at 20 characters, keeping word boundaries intact.

fold -w 20 -s frost.txt