Linux Create and save a new text file called Gasoline that consists of the follo
ID: 3774474 • Letter: L
Question
Linux
Create and save a new text file called Gasoline that consists of the following content:
Gas prices rose only half a penny a gallon in the past two weeks, continuing an unusual 20-week trend of mostly steady prices. The average price for gas nationwide, including all grades and taxes, was about $2.46 a gallon on Friday, according to a survey of 8,000 stations released Sunday. That was up .5 cents per gallon from Aug. 9. Prices have shown little change since early April, when a gallon of gas also cost about $2.46.
Step 4: Create an analysis script called TestScript that completes the following tasks for the Gasoline file:
Remove punctuation
Make all characters lowercase
Put each word on a single line
Remove blank lines
Sort the text to put all lines containing the same word on adjacent lines. Hint: Use | sort | uniq -c for this part.
Remove duplicate words from the text
List most-used words in the file first
Send the output of this script to a file named ScriptResult. Hint: Use the tee command for this part.
Step 5: Verify that the script was created successfully.
Step 6: Make the TestScript executable.
Step 7: Run the script.
Explanation / Answer
#Take the data in a file called test.txt
cat test.txt | tr -d '[:punct:]' |tee a.txt # to remove punctuation
cat a.txt | tr "[:upper:]" "[:lower:]" |tee b.txt # to change all upper case letters to lower case letters
cat b.txt | tr ' ' ' ' |tee a.txt # to arrange all the words in a new line and removing blank lines
cat a.txt |sort|uniq |tee b.txt # to sort all the words and remove duplicate words
#tee command is used to display the output on console and at the same time transfer the output to any file .
Finally the output is available in b.txt.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.