Use two field separator in the same line and print them

Hi Guys,

I have the file

---

HOST_NAME,data_coleta,data_carga,CPU_util,CPU_idle,run_queue,memory,MEMORY_SYSTEM,MEMORY_TOTAL,MEMORY_SWAPIN,MEMORY_SWAPOUT,DISK_READ,DISK_WRITE,DISK_IO,NET_IN_PACKET,
NET_OUT_PACKET
bd-bkp-sjp,01/06/2015,03/06/2015,3.1908333333,99.8725,0.8333333333,20.649166667,0.55,21.199166667,0,0,192.98333333,1207.3083333,144.65,60.008333333,55.35
bdurasip,01/06/2015,03/06/2015,0.2608333333,99.755833333,0.5833333333,8.8458333333,0.28,9.1258333333,0,0,91.283333333,29.325,2.2,43.275,78.966666667
bd2-rj,01/06/2015,03/06/2015,12.168333333,87.866666667,1.4166666667,9.3791666667,0.27,9.6491666667,0,0,0.2166666667,49.775,2.6583333333,17.041666667,17.241666667

----

I can print it with

awk -F"," '{print " "$2";"8600";"$1";CPU_UTIL;SYSGLB;"$4";"$1" "}' $FILE

Output:

01/06/2015;8600;cl-wfl-01;CPU_UTIL;SYSGLB;49.974166667;cl-wfl-01
01/06/2015;8600;cl-wfl-02;CPU_UTIL;SYSGLB;1.7383333333;cl-wfl-02
01/06/2015;8600;cl-wrf-01;CPU_UTIL;SYSGLB;88.7825;cl-wrf-01

But I need to change the datetime format to YYYY-MM-DD

I can do this with

echo "19/05/2015" | awk -F/ '{printf "%s%02s%02s\n", $3"-", $2"-", $1}'

But I don't know how put it together in the same line.... Anyone can help me please?

Thanks in advanced
Best Regards
Antonio

Antonio,

Your output does not reflect what your data says. I get:

awk -F"," '{print " "$2";"8600";"$1";CPU_UTIL;SYSGLB;"$4";"$1" "}' antonio.file
 data_coleta;8600;HOST_NAME;CPU_UTIL;SYSGLB;CPU_util;HOST_NAME
 01/06/2015;8600;bd-bkp-sjp;CPU_UTIL;SYSGLB;3.1908333333;bd-bkp-sjp
 01/06/2015;8600;bdurasip;CPU_UTIL;SYSGLB;0.2608333333;bdurasip
 01/06/2015;8600;bd2-rj;CPU_UTIL;SYSGLB;12.168333333;bd2-rj

The following gives me:

awk -F","  'FNR>1 {split($2, a, "/"); print a[3]"-"a[2]"-"a[1], "8600", $1, "CPU_UTIL", "SYSGLB", $4, $1}' OFS=";" antonio.file
2015-06-01;8600;bd-bkp-sjp;CPU_UTIL;SYSGLB;3.1908333333;bd-bkp-sjp
2015-06-01;8600;bdurasip;CPU_UTIL;SYSGLB;0.2608333333;bdurasip
2015-06-01;8600;bd2-rj;CPU_UTIL;SYSGLB;12.168333333;bd2-rj

Which I think is what you want.

1 Like

Aia,

You are correct I forgot remove the header file...

I'll study the split command I'v never seen it....

You save!! Thank you very much!!!

Thanks again
Best Regards

Muy facil.

split($2, a, "/")

$2 is the string you want to split
a is any user given variable name
"/" is the separator that you want to split from
After that, you can retrieve the values by using a[1], a[2], a[3]...

1 Like

split will return the element count: n=split($2, a, "/") , so you will know where/when to stop looking for elements, e.g. for (i=1; i<=n; i++) print a