1

I have a log file as below,

011122111128 :16267281288 :40586200370017022 :947700000622 :919400146760221 :SSD :4065376D : :9477000006 :9170120275030 :210 :18 :002919544716189 :unknown :unknown :unknown

I need to print each line(always I need to get last 50 records) with a comma-separated line then I can import it as a CSV file. Here is the required output.

011122111128,16267281288,40586200370017022,947700000622,919400146760221,SSD,4065376D,,9477000006,9170120275030,210,18,002919544716189,unknown,unknown,unknown

Here is what I tried but this prints the first value only and it not takes the last 50 records also. Can someone help me with the below?

awk -F ':' '{print $1}' /log
edublog
  • 83
  • What do you mean by always I need to get last 50 records? Do you need to separate by a comma the last 50 records of each line (so from columns 1 to 49 will not be separated by a comma)? – Edgar Magallon Nov 01 '22 at 07:07
  • No, this is a log. There are so many lines as I showed .I need last 50 records only. tail -50. – edublog Nov 01 '22 at 07:09
  • Btw it seems the site is not working well for the moment. Your question (unless in my case) is not visible in the Questions Section. I was able to found your question by using https://unix.stackexchange.com/questions/723200 (I typed the number) and there are more recent questions whose can be acceded by changing 723200 for 723199 for example. – Edgar Magallon Nov 01 '22 at 07:12
  • And thanks for the clarification! I will try to provide a solution – Edgar Magallon Nov 01 '22 at 07:12

1 Answers1

1

If you only want to get the last 50 records to convert to a csv file (comma separated) then you should use:

tail -50 /log | sed 's/\s:/,/g' > /some_path/data.csv