遍历 csv 文件,为每个文件输出 tail -n 到新的 csv
Loop over csv files, output tail -n to new csv for each
我正在编写一个 bash 脚本,它循环遍历 x 个日志文件并将每个日志文件的最近 10 个条目发送到一个单独的 csv 中。因此,如果我有 25 个日志文件,在 运行 脚本之后我将期望有 25 个新的 csv 文件,每个文件包含 10 个最近的行。
这是我正在尝试做的事情:
#!/bin/bash
for file in /path/to/logs/*.log;
do tail -n 10 > "$file".csv
done
我似乎无法让它遍历所有文件 - 相反,它挂在一个文件上。如何让这个小片段遍历每个文件?
我认为您在 tail 命令中缺少 $file 参数。您可以尝试在它的末尾添加“$file”吗?
#!/bin/bash
for file in /path/to/logs/*.log;
do tail -n 10 "$file" > "$file".csv
done
我正在编写一个 bash 脚本,它循环遍历 x 个日志文件并将每个日志文件的最近 10 个条目发送到一个单独的 csv 中。因此,如果我有 25 个日志文件,在 运行 脚本之后我将期望有 25 个新的 csv 文件,每个文件包含 10 个最近的行。
这是我正在尝试做的事情:
#!/bin/bash
for file in /path/to/logs/*.log;
do tail -n 10 > "$file".csv
done
我似乎无法让它遍历所有文件 - 相反,它挂在一个文件上。如何让这个小片段遍历每个文件?
我认为您在 tail 命令中缺少 $file 参数。您可以尝试在它的末尾添加“$file”吗?
#!/bin/bash
for file in /path/to/logs/*.log;
do tail -n 10 "$file" > "$file".csv
done