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

file in Unix: ------------------------------------------------------------------

ID: 3870019 • Letter: F

Question

file in Unix:

-----------------------------------------------------------------------------------------------------------

Table: Eleven highest mountains in Georgia

Brasstown Bald ,(summit),4784,feet,Union County

Rabun Bald, (summit),4696,feet,Rabun County

Dick's Knob, (summit),4620,feet,Rabun County

   Hightower Bald, (summit),4568,feet,Towns County

Wolfpen Ridge, (ridge high point),4561,feet,Towns and Union Counties

Blood Mountain, (summit),4458,feet,Union County

Tray Mountain, (summit), 4430,feet,Towns County

   Grassy Ridge, (ridge high point),4420,feet,Rabun County

Slaughter Mountain, (summit),4338,feet,Union County

Double Spring Knob, (summit),4280,feet,Rabun County

Coosa Bald, (summit),4280,feet,Union County

--------------------------------------------------------------------------------

Which command is used to achieve those below in Unix/Linux:

1. Use sed to remove the middle three fields in each line of "mountainList.txt". Hint: Think about the meaning of regex '[^,]'

2. Use sort to print out the sorted lines in alphabetical order according to the

names of mountains.

3. Use sort to print out the sorted lines in descending order according to the height of mountains.

4. “When a pattern groups all or part of its content into a pair of parentheses, it captures that content and stores it temporarily in memory. You can reuse that content if you wish by using a back-reference, in the form: or $1, where  or $1 reference the first captured group” (Refer to [1]). For example, the following command add a colon between Union and County

Now can you write a command to finish task 1) using sed with back- reference?

Explanation / Answer

I dont have unix shell with me, i am using online unix shell:

1)

bash-4.4$ echo "BrassTown Blad,(summit),4784,union county" | sed 's/,[^,]*,[^,]*,/,/'                     

BrassTown Blad,union county

2)  sort -k1 -n -t , filename

here -k1 states that sort by cloumn 1 in ascending order

-t for specifing delimeter.

use this if the above command throws error

3)

here -r stands for reverse.