Check the field (item name) before awk. The field is usually on the first line of the (?) File, so use less or head to check it.
head -1 File name
I think that field names are often written with commas without line breaks or separated by pipes. Rather than counting visually to see "what number of fields the target column is" It is safe and efficient to change the delimiter to a newline using a Sakura editor. Copy the output field.
In the Sakura editor, Ctrl + r (replace), check the regular expression in the dialog box, Replace the delimiter with "\ r \ n (line feed)".
You can tell which column is in the row number.
For those who do not use Sakura Editor. Introducing how to replace delimiters in Excel. (* Regular expressions cannot be used in Windows Notepad, so they cannot be replaced with line breaks, etc.)
First, paste the character string into Excel. Select Ctrl + h or Replace from Home tab> Edit group to display the dialog. "Search string": (Enter the delimiter) "Character string after replacement": Press ** Ctrl + j ** (a symbol like a dot is displayed, but this means a line break) After the above, click Replace All Since it is output in one cell, select all copy after entering edit mode by F2 or double click. Paste after exiting edit mode In this state, go to Home tab> Edit group> Search and select> Select conditions and jump From the selection options dialog, select a blank cell and OK Right click on the selected blank cell> Delete> Select entire row and OK The data is arranged vertically.
** If you want to get the sum of \ $ 40 and \ $ 50 respectively **
Pipe the cated value to awk. ▼
cat [file name] | awk -F "," '{ print a += $40; b += $50 } END { print a, b }' |tail -1
Recommended Posts