简体   繁体   English

在 linux 中计算多个 csv 文件中的行和文本字符串并通过管道传输到 csv 文件

[英]Count lines and text strings in muliple csv files in linux and pipe to a csv file

How would i traver though a folder containing multiple cvs files and:我将如何遍历包含多个 cvs 文件的文件夹以及:

  1. Count non-empty lines计算非空行
  2. Count lines containing: a.计数包含以下内容的行: "Time Out" b. “超时” B. "Mortality" c. “死亡” C. "Init" “在里面”

An pipe that to a csv file in the format:以以下格式连接到 csv 文件的管道:

Filename "Line Count" "Time Out" "Mortality" "Init"文件名“行数”“超时”“死亡率”“初始化”

in command line in Linux?在 Linux 的命令行中?

Edit:编辑:

wc -l ./*.csv > result.txt

And was able to get the count of the lines, but am unsure about find strings as stated above.并且能够获得行数,但我不确定如上所述查找字符串。

I edited according to shellcheck.net and got this:我根据 shellcheck.net 编辑并得到了这个:

#!/bin/bash

find ./ -type f -exec cat {} > /tmp/file.tmp \;
cmd /tmp/file.tmp | grep Time Out | grep Mortality | grep Init > /tmp/file2.tmp
wc -l /tmp/file.tmp
rm /tmp/file.tmp

You could use this script (may not be optimal for periodic use):您可以使用此脚本(可能不适合定期使用):

!/bin/bash

find ./ -type f -name "*.csv" -exec cat {} \; | grep Time Out | grep Mortality | grep Init > /tmp/file.tmp
wc -l /tmp/file.tmp
rm /tmp/file.tmp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM