I have full list of files which contains this below texts.
Sun Aug 22 19:00:00 2021
User-Name = "407359687"
Acct-Status-Type = Interim-Update
Acct-Output-Octets = 3263901190
Acct-Session-Id = "PPP3092201SSG0001006b0a55AABODS"
Acct-Session-Time = 1146851
Acct-Output-Gigawords = 15
Event-Timestamp = "Aug 22 2021 18:55:32 +08"
Timestamp = 1629630000
My goal is to get the important rows and save it into new CSV file and i'm using this below AWK command to sort the values from text but I don't know to write it into CSV file.
awk '{if ($1 == "User-Name")
{start=1; wholeLine=""; wholeLine = wholeLine$3;}
if ($1$2$3 =="Acct-Status-Type=Interim-Update"||$1$2$3 =="Acct-Status-Type=Stop")
{wholeLine=wholeLine","$3;}
else if ($1$2$3 =="Acct-Status-Type=Start")
{start=0;wholeLine=""}
if (($1=="Acct-Output-Octets")&&(start==1))
{wholeLine=wholeLine","$3;}
if (($1=="Acct-Session-Id")&&(start==1))
{wholeLine=wholeLine","$3;}
if (($1=="Acct-Session-Time")&&(start==1))
{wholeLine=wholeLine","$3;}
if (($1=="Acct-Output-Gigawords")&&(start==1))
{wholeLine=wholeLine","$3;}
if (($1=="Event-Timestamp")&&(start==1))
{timeStamp="";timeStamp=$3" "$4" "$5" "$6" "$7;wholeLine=wholeLine","timeStamp}
if (($1=="Timestamp")&&(start==1))
{wholeLine=wholeLine","$3;}
if (($1=="")&&(start==1))
{start=0;print wholeLine}}' /home/file/detail-20210822
My expected CVS result should be look like this.
"405947674",Interim-Update,1079493624,"PPP3082110SSG000100be4a72AAAk5Y",25440,0,"Aug 22 2021 19:00:43 +08",1629630315
awk ... > output.csv. If that is not your problem, what is it?if ... else if ... else if ..., use awk's patterns, e.g./$1=="User-Name"/ { start=$1; ... }.