How to parse a log file with bash and output results to an HTML table?

I am trying to parse a log file using bash.

File content example:

1234.567  1.1.1.1  2.2.2.4  10  GET  info.com  { Mozilla/5.0 (Windows NT 6.1; WOW64) }
2357.693  2.2.2.2  3.3.3.4  20  GET  example.com  { Mozilla/5.0 (Intel MAC OS X }

I am trying to get the information above to be put into an HTML table for viewing on a website. I want the headers to be Time Stamp, Source IP, Destination IP, Destination Port, HTTP METHOD, Target HOST, Browser, and OS. I'm not really sure how to begin parsing it. I've tried looking up ways to parse it, but nothing is helping me figure out how to begin.

Hello,

Welcome to the forum ! We hope you enjoy your time here, and find this to be a friendly and helpful place.

The way we typically try to help our users here is to ask in the first instance to see what they have tried so far. Now, you mention that you have no idea how to begin. Well, one good place to start would be to look at one of the most typical ways of selecting portions of a given piece of input, which is via the use of awk.

To see an example of how to do this, there are various threads here on the forum which have discussed this over the years, but one of the more recent ones I remember helping someone with would be this one:

Transfer data from log file to excel

Have a read over that, and give it a go - try implementing a solution that picks out the pieces of input that you require, and let us know how you get on. Also, when you get back to us, if you could provide information on your environment (e.g. operating system, hardware platform, shell, etc), that would be great.

Hope this helps !

1 Like

@anon14307900 , Please note the team are here to assist/guide you in coming to a solution BUT not to write the code for you. some basic questions , please, answer ALL of them.

  • is this homework/coursework/paid-work ?

  • have you written any code to attempt to parse,generate the table ?

  • if yes, please share that here with output generated when you ran that code.

  • what is your experience of writing shell scripts (scripts in general - say in perl/ruby/python/awk etc)

  • what is your experience of writing html/css ?

decent educational sources for html/css - there are many, here's 1 and an online editor to help you experiment:
https://www.w3schools.com/html/default.asp
https://htmleditor.w3schools.in/

i presume that something along like the image below is what you are attempting ( this took around 30 mins to code/test ).

as mentioned by other team members there are many ways of achieving this.

@anon14307900 , yes it is possible - my example was written in awk ( i did not post the code as I don't want to write your code :slight_smile: ) , however, you asked for it in bash - that has been given by @bendingrodriguez and @MadeInGermany has given an example in perl, why not play around with both of those first and become comfortable with them.

1 Like

When people say "they have no experience writing scripts" and then ask for a specific solution in awk, this means the user is hiding they fact they are doing homework.

People with twist themselves into a pretzel to get others to do their work for them on the net. Let's stop writing others code when the user refuses to even write a single line of code.

1 Like

I'm closing this topic.

Please do not post homework / classwork disguised as "real work" @anon14307900 specifying a solution in a certain language; because you have a requirement to do this work in that language, which means you are doing homework and not being totally honest with us.

Second, you have show zero effort on your side.

Everyone, please stop writing code for posters who show no effort what-so-ever!