Convert file in csv or table

Hi there,
i have a file like that in attachment (PLEVA3_280711_SAP.txt), i would extract some basic information from it and report in a new file or table like this:
i try to use bash and i extract the single object in this way (see attach scriptino.sh), but i receive a strange output(strange.txt), can someone help me to write this script?

NAME | WWN | CAPACITY | RAID | PRESENTATION
-----------------------------------------------------------
vdisk1 |6005-.. | 200 | 5 |host1
|host2
-----------------------------------------------------------

How about this ?

 
 awk -F":" '
   /objectname/ {f1=1;o=$2;next}
   /wwlunid/ {f2=1;w=$2;next}
   /allocatedcapacity/ {f3=1;a=$2;next}
   /redundancy/ {f4=1;r=$2;next}
 f1&&f2&&f3&&f4{printf "%s|%s|%s|%s\n",o,w,a,r;f1=f2=f3=f4=0}'  PLEVA3_280711_SAP.txt

Do the other needed formatting.

1 Like

Thks panyam,
can you explain me the script, i try to interpret it but i don't understand:
with /objectname/ i find line with this patterns, what is the meaning of expression in braces?
the printf is clear also if i don't understand f1=f2=f3=f4=0.
thks and sorry if i bored.

 /objectname/ {f1=1;o=$2;next} --> if "objectname" present in a line store second field in variable "o" and set f1 flag

repeat the same login for other variables as well.

Once all the four values are available , print them and reset the flags f1,f2,f3,f4 to 0 again ( to avoid print other lines).

1 Like

and if i would add a fifth column with multiple value? I must see sometimes like:
NAME |WWN |CAPACITY | RAID | PRESENTATION
-----------------------------------------------------------
vdisk1 |6005-.. |200 |5 |host1,host2,host3
vdisk2 |6004-.. |100 |1 |host 18,host23

Can you said me where can i found this type of information in some manual of awk?
Thanks
AN

Best place to start/learn