1

I need to create a report file from csv files.

I have 160 devices named like MR001 to MR160, there is a folder for each one, all the folders have a unique ID that start with 4, and there is a csv file per day named like MRNNN_Log_AAAAMMDD-NN.csv.

the csv file content are like this:

MR092/16.11.2017/13:50:50-0300/WLLocalSearch/Error
MR092/16.11.2017/13:51:10-0300/WLLocalSearch/Hit
MR092/16.11.2017/13:51:25-0300/WLLocalSearch/NoHit
MR092/16.11.2017/13:51:35-0300/WLLocalSearch/Error
MR092/16.11.2017/13:51:41-0300/WLLocalSearch/Error
MR092/16.11.2017/13:52:02-0300/RemoteSearch/Captured
MR092/16.11.2017/13:52:53-0300/RemoteSearch/Hit

I'm trying with a command like this:

#!/bin/bash

date=$1

find /path/4*/*_Log_$1*.csv -printf 'echo "$(grep -o "/WLLocalSearch/NoHit" %p | wc -l) %p";' | sh
find /path/4*/*_Log_$1*.csv -printf 'echo "$(grep -o "/WLLocalSearch/Hit" %p | wc -l) %p";' | sh
find /path/4*/*_Log_$1*.csv -printf 'echo "$(grep -o "/WLLocalSearch/Error" %p | wc -l) %p";' | sh

I executed the script like this:

./report.sh AAAANN

The output is like this

25 /path/path/MR001_Log_20190415-00.csv
4 /path/path/MR002_Log_20190415-00.csv
10 /path/path/MR007_Log_20190415-00.csv
7 /path/path/MR090_Log_20190415-00.csv
etc...

the problem is that I have no idea how to sum the total per type and device ID, like this

MR001 Hit 10
MR002 Hit 5

Etc..

  • You can find the csv files from filename pattern with date, then read multiple variables into an array and, at last, output the array to screen or to a new csv file – cmak.fr May 19 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.