7) Use sed to list the lines beginning with white spaces in \"mountainList.txt\"
ID: 3871100 • Letter: 7
Question
7) Use sed to list the lines beginning with white spaces in "mountainList.txt".
8) Use sed to delete the lines where the mountains are only at Union County in "mountainList.txt".
9) Use sed to remove the middle three fields in each line of "mountainList.txt". Hint: Think about the meaning of regex '[^,]'
10) Use awk to finish task 9).
11) Use sed to insert a new line “Table: Eleven highest mountains in Georgia” at the beginning of "mountainList.txt".
12) Use sort to print out the sorted lines in alphabetical order according to the names of mountains.
13) Use sort to print out the sorted lines in descending order according to the height of mountains.
14) “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 sed -E ‘s/(Union)s(County)/:/g’ mountainList.txt
15)Now can you write a command to finish task 9) using sed with back- reference?
Explanation / Answer
7) sed -n -e '/^ /p' mountainList.txt
8) sed -i '/Union County/d' mountainList.txt
9) sed -i -r 's/,+//2' mountainList.txt
sed -i -r 's/,+//2' mountainList.txt
sed -i -r 's/,+//2' mountainList.txt
10) awk '!($3="")' mountainList.txt>mountainList.txt
awk '!($3="")' mountainList.txt>mountainList.txt
awk '!($3="")' mountainList.txt>mountainList.txt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.