(edit: Problem solved, I used windows-generated files on a mac and the problem was the line endings. opening the file in studio code and setting proper line endings solved this for me)
I have files generated by ProduKey that I want to process with awk.
ProduKey produces output like this:
==================================================
Product Name : Microsoft Office Professional 2013
Product ID : 00000-00000-00000-00000
Product Key : 00000-00000-00000-00000-00000
Installation Folder : C:\Program Files\Microsoft Office\Office15\
Service Pack :
Build Number :
Computer Name : PC-000-0
Modified Time : 06.12.2018 14:03:44
==================================================
==================================================
Product Name : Windows 10 Pro
Product ID : 00000-00000-00000-00000
Product Key : 00000-00000-00000-00000-00000
Installation Folder : C:\Windows
Service Pack :
Build Number : 17763
Computer Name : PC-000-0
Modified Time : 18.07.2019 09:50:37
==================================================
I want to generate csv files from that to store key, computer name and product name to a database later.
so a possible csv could look like this:
PC-000-0;Microsoft Office Professional 2013;00000-00000-00000-00000-00000
My approach so far:
BEGIN {
RS="\n\n";
FS="\n";
}
{
if ($1 ~ /Product Name/) {
split($1,productArray,":")
product = productArray[2]
}
if ($1 ~ /Product Key/) {
split($1,keyArray,":")
key = keyArray[2]
}
if ($1 ~ /Computer Name/ ) {
split($1,computerArray,":")
computer = computerArray[2]
#print product
#print key
#print computer
printf("\n")
printf("%s ; %s ; %s \n", computer, product, key)
}
}
My problem is that I cannot concat the strings. Or maybe the strings are overriden by the moment i want to print them? I spend hours on this and would really appreciate your help/hints.
If there are more elegant ways to reach my goal feel free to tell me.
I am using awk on a Mac (awk version 20070501) but I have a Linux box as well.
Thanks in advance.