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

Cars text file: 2. Converting Multiline Files to Flat Files -- carsconvert We ha

ID: 3714284 • Letter: C

Question

Cars text file:

2. Converting Multiline Files to Flat Files -- carsconvert We have seen that many Linux tools are designed to process flat file data files (files having one or more fields per line with some field separator, and each line is a separate record). However, sometimes the data file may be derived from sources that do not produce flat files. In this problem you will convert a multiline line data file to a flat file form. The multiline file is the cars file. The format of this file is a group of 4 lines that include fields from three records. Each line has tab- separated fields, 3 fields per line. Each of these fields belongs to 3 different records. Thus each record consists of 4 fields, 1 from each of the group of 4 lines. The group of 4 lines may be repeated as many times as necessary to provide all of the data. The schema below may help illustrate the file format: F1-R1 F1-R2 F1-R3 F2-R1 F2-R2 F2-R3 F3-R1 F3-R2 F3-R3 F4-R1 F4-R2 F4-R3 This group of 4 lines is repeated as many times as necessary Fn denotes field n, Rn denotes record n The script should convert this to a flat file in which each record is on one line with all fields for that record. The script should create the flat file with comma separated fields. Thus the above 4 lines would be converted to: F1-R1,F2-R1,F3-R1,F4-R1 F1-R2,F2-R2,F3-R2,F4-R2 F1-R3,F2-R3,F3-R3,F4-R3 Careful observation of the data file will reveal the need to make some minor edits these should be 1) Some fields have one or more spaces after the field data prior to the tab removed without removing the internal space within the field itself. 2) Some fields incorporate ,' as part of the field value. This would make processing of the resulting file more difficult since we want to use ',' as the field separator. These commas should be removed before writing the final result. 3) name the output file (notthe script file) newcars. When complete, save the script as carsconvert in your ee462 directory in your AFS file space. You don't need to upload the newcars file since it is an output file.

Explanation / Answer

The awk solution for the above problem is as follows:

But before proceeding further, let me tell you something about awk. Do you all know what exactly the awk means?

The awk command is included by default in all modern Linux system. So we do not need to install.

Awk is derived from the names of developer - Aho, Weinberger, and Kernighan. It is mainly used for pattern scanning and processing.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote