如何解析 csv 文件以在第 2 列的文件中找到 "fails" 并找到第 7 列的平均值

How do I parse a csv file to find the "fails" in the file which is on column 2 and find the average of column 7

grep "false"  | cut -d ',' -f2,7

这是我得到的。有了这个我可以得到所有的假错误和他们的响应时间。但是我很难从所有响应时间的组合中找到平均值。

It's not fully clear what you're trying to do, but if you're looking for the arithmetic mean of all second comma-delimited fields ("columns") where the seventh field is false then here's an answer using awk:

awk -F ',' ' == "false" { f++; sum +=  } END { print sum / f }' "$@"

This sets the field separator to be , and then parses only lines whose seventh (comma-delimited) field is exactly false (also consider tolower() == "false"), incrementing a counter (f) and adding the second column to a sum variable. After 运行 through all lines of all input files, the script prints the arithmetic mean by dividing the sum by the number of rows it keyed on. The trailing "$@" will send each argument to your shell script as a file for this awk command.

A note on fields: awk is one-indexed, but 0 often has a special value. [=22=] is the whole line, </code> is the first field, and so on. <code>awk is pretty flexible, so you can also do things like $i to refer to the field represented by a variable i, including things like $(NF-1) to refer to the contents of the field before the last field of the line.

Non-delimiting commas: If your data might have quoted values with commas in them, or escaped commas, the field calculation in awk (or in cut) won't work. A proper CSV parser (requiring a more complete language than bash plus extras like awk, sed, or cut) would be preferable to making your own. Alternatively, if you control the format, you can consider a different delimiter such as Tab or the dedicated ASCII Record Separator character (RS, a.k.a. U+001E, Information Separator Two, which you can enter in bash as $'\x1e' and in awk (and most other languages) as "\x1e").