Convert log files to CSV

Solved
lisarlt -  
Pierrecastor Posted messages 10830 Registration date   Status Moderator Last intervention   -
Hello,

I have several log files (located in a folder called inputs) that I would like to transform into a single csv file using a shell script.
I thought I should first group them into a single log file (result.log)?
I wrote:
cat ./inputs/*.log > ./inputs/result.log;
for i in `find ./inputs`
do
echo ${i}
echo "$(cat ${i})"
done;

How can I ask for the file to be transformed into csv?
Thank you in advance.

3 answers

Pierrecastor Posted messages 10830 Registration date   Status Moderator Last intervention   4 215
 
Hello,

Technically, a CSV file and a log file are just text files with different extensions.

Normatively, the CSV contains hierarchical information separated by semicolons that can be imported into a spreadsheet or a database.

Basically, without knowing more specifically what you want to do, it's hard to respond.

For the code, you have the code sh tag in the forum to maintain the formatting. It's the arrow to the right of the <> icon.
--
Light a fire for someone and they will be warm for the rest of the day. Set a man on fire and he will be warm for the rest of his life. -Terry Pratchett-
0
lisarlt
 
Thank you for your response and for the clarification about the code tag; this is my first time writing here.
My log files consist of 3 simple columns of numbers that allow me to inventory the number of products I have over the year.
These files are therefore located in my structure within the inputs folder.
However, to visualize them, I used to execute each file and retrieve their contents to consolidate them into a Excel file manually.
I would like to automate this process and run a single shell script that would email me the CSV file containing all the log data.
I'm not sure if my explanation is clear enough...
I am very new to shell.
0
Pierrecastor Posted messages 10830 Registration date   Status Moderator Last intervention   4 215
 
Can you put an example of a log file here?

--
Light a fire for someone and they will be warm for the rest of the day. Set a man on fire and he will be warm for the rest of his life. -Terry Pratchett-
0
lisarlt
 
week year max_conns

29 2021 35
28 2021 42
27 2021 43
26 2021 41
25 2021 39
24 2021 75
23 2021 45
22 2021 63
21 2021 59
20 2021 82
19 2021 81
18 2021 56
17 2021 47
16 2021 37
15 2021 48
14 2021 44
13 2021 53
12 2021 54
11 2021 125
10 2021 44
9 2021 46
8 2021 72
7 2021 45
6 2021 40


I did a simple copy-paste. They all look pretty much like this.
0
Pierrecastor Posted messages 10830 Registration date   Status Moderator Last intervention   4 215
 
Ok, it should be imported without any issues, but there will be redundancies with the column titles: week year max_conns

Does the concatenation script work? What does it output?
--
Light a fire for someone and they will be warm for the rest of the day. Set a man on fire and he will be warm for the rest of his life. -Terry Pratchett-
0
lisarlt
 
 cat ./inputs/*.log > ./inputs/result.log; for i in `find ./inputs` do echo ${i} echo "$(cat ${i})" done; 


I have written this script so far.
Running this script returns all the logs one after the other in the console and creates a result.log file containing them.
And then it's a dead end. I've done some research but I don't know how to create the csv file, so I haven't written anything else that works.
0
Pierrecastor Posted messages 10830 Registration date   Status Moderator Last intervention   4 215 > lisarlt
 
Simply rename it:

mv result.log result.csv
0
lisarlt > Pierrecastor Posted messages 10830 Registration date   Status Moderator Last intervention  
 
ahhh I didn't know!! but it works!
Thank you very much, sorry for wasting your time...
0
Pierrecastor Posted messages 10830 Registration date   Status Moderator Last intervention   4 215 > lisarlt
 
As I mentioned earlier, it's just the extension that changes.

There should even be a way to remove the first two lines of each file to avoid having "week year max_conns" when returning to the columns, but that goes beyond my level of bash.

And it's not wasted time, but shared. ;-)
0