Question: Finish task 11) using sed with back-reference.
11) Use sed to list only the company number and company name on each line by checking "newList.txt".
E.g. line 1 in the output is "1.The Home Depot"
E.g. line 12 in the output is "12.Mohawk Industries, Inc"
1.The Home Depot (Ranked 28): home improvement; Atlanta, GA.
2.United Parcel Service (Ranked 48): shipping; Atlanta, GA.
3.The Coca-Cola Company (Ranked 62): soft drinks; Atlanta, GA.
4.Delta Air Lines, Inc. (Ranked 68): airline; Atlanta, GA.
5.Aflac, Incorporated (Ranked 135): insurance; Columbus, GA.
6.The Southern Company (Ranked 162): energy; Atlanta, GA.
7.Genuine Parts Company (Ranked 183): replacement parts; Atlanta, GA.
8.First Data Corporation (Ranked 249): payment processing; Atlanta, GA.
9.WestRock (Ranked 251): corrugated and consumer packaging; Norcross,
GA.
10.HD Supply Holdings, Inc. (Ranked 320): industrial distributors; Atlanta,
GA.
11.Suntrust Banks, Inc. (Ranked 329): banking; Atlanta, GA.
12.Mohawk Industries, Inc. (Ranked 338): flooring manufacturer; Calhoun,
GA.
The solution to the above question is given below with screenshot of output.
=====================================================
I kept the logic simple and i have tested all outputs.
I Have added comments in program so that it can be easily
understood.
If there is anything else do let me know in comments.
=====================================================
file used :
newList.txt
1.The Home Depot (Ranked 28): home improvement; Atlanta, GA.
2.United Parcel Service (Ranked 48): shipping; Atlanta, GA.
3.The Coca-Cola Company (Ranked 62): soft drinks; Atlanta, GA.
4.Delta Air Lines, Inc. (Ranked 68): airline; Atlanta, GA.
5.Aflac, Incorporated (Ranked 135): insurance; Columbus, GA.
6.The Southern Company (Ranked 162): energy; Atlanta, GA.
7.Genuine Parts Company (Ranked 183): replacement parts; Atlanta, GA.
8.First Data Corporation (Ranked 249): payment processing; Atlanta, GA.
9.WestRock (Ranked 251): corrugated and consumer packaging; Norcross, GA.
10.HD Supply Holdings, Inc. (Ranked 320): industrial distributors; Atlanta, GA.
11.Suntrust Banks, Inc. (Ranked 329): banking; Atlanta, GA.
12.Mohawk Industries, Inc. (Ranked 338): flooring manufacturer; Calhoun, GA.
============ CODE TO COPY ===========================
COMMAND :
cat newList.txt | sed -E 's/([0-9])\.([^(]*)(.*)/\1.\2/'
or
sed -E 's/([0-9])\.([^(]*)(.*)/\1.\2/' newList.txt
=====================================================
Output :
Question: Finish task 11) using sed with back-reference. 11) Use sed to list only the company...