![]() In the previous section, we parsed the field values into Bash variables for each record. Subsequently, we searched the column name in the output using the grep command and truncated the preceding spaces using the tr command.įinally, we used the awk command to get the first field, which corresponds to the column number. Then, we appended the line number at the beginning of each line using the nl command. We calculated the location of a column using the combination of tr, awk, grep, and nlcommands.įirst, we converted the commas in the header line into line-breaks using the tr command. ![]() This script takes col_b as input from the user and prints the corresponding column value for every record in the file. Read -p "Enter the column name to be printed for each record: " col_b ![]() Let’s illustrate this with a simple user-input-driven script: #! /bin/bash There can be situations where we might need to parse the values from CSV based on column names in the header line.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |