Convert log files to CSV
Solved
lisarlt
-
Pierrecastor Posted messages 10830 Registration date Status Moderator Last intervention -
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.
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
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-
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-
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-
--
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-
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.
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.
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-
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-
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.
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.