Convert file in csv or table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert file in csv or table
# 1  
Old 07-29-2011
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
-----------------------------------------------------------
# 2  
Old 07-29-2011
How about this ?

Code:
 
 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.
This User Gave Thanks to panyam For This Post:
# 3  
Old 07-29-2011
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.
# 4  
Old 07-29-2011
Code:
 /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).
This User Gave Thanks to panyam For This Post:
# 5  
Old 08-24-2011
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
# 6  
Old 08-24-2011
Best place to start/learn

www.grymoire.com/Unix/Awk.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search in a file and convert in a table

Hi to all, I have a file like that in attach, I need to create a table or csv with only this field: "Barcode","Device Name", "ACSL". I tried with grep with -B options but the number of lines are different for any block is different, there is a method with sed or awk to extract it. Thanks a... (2 Replies)
Discussion started by: alen192
2 Replies

2. UNIX for Beginners Questions & Answers

1. This will insert the records into db table by reading from ta csv file

I have this code with me but the condition is If any of the mandatory columns are null then entire file will be rejected. LOAD DATA infile ' ' #specifies the name of a datafile containing data that you want to load BADFILE ' ' #specifies the name of... (1 Reply)
Discussion started by: raka123
1 Replies

3. UNIX for Dummies Questions & Answers

Convert Txt file to HTML table and email

Hi all I need help converting a text file into a html table in bash and I need to email this table. The text file looks like the below. Two columns with multiple rows. Top row being header. Application Name Application Status Application 1 Open Application 2 ... (2 Replies)
Discussion started by: hitmanjd
2 Replies

4. Shell Programming and Scripting

Create a pivot table from CSV file

Gents, Can you please help me to create a pivot table from a csv file. ( I have zip the csv file) Using the file attached, columns 1,28 and 21 i would like to get something like this output JD Val 1 2 3 4 5 6 7 8 9 10 11 12 Total... (4 Replies)
Discussion started by: jiam912
4 Replies

5. Shell Programming and Scripting

awk to convert table-by-row to matrix table

Hello, I need some help to reformat this table-by-row to matrix? infile: site1 A:o,p,q,r,s,t site1 C:y,u site1 T:v,w site1 -:x,z site2 A:p,r,t,v,w,z site2 C:u,y site2 G:q,s site2 -:o,x site3 A:o,q,s,t,u,z site3 C:y site3 T:v,w,x site3 -:p,routfile: SITE o p q r s t v u w x y... (7 Replies)
Discussion started by: yifangt
7 Replies

6. Shell Programming and Scripting

Update the table using values from a csv file

i want to run update query for oracle which is in up.sql taking values from a.csv. I have implemented shell script to do it. extn="perl" ls -1 | while read file do echo "$file,$extn" > a.csv done up.sql contains update file_list set filename=$1 where extn=$2; The code to update is... (2 Replies)
Discussion started by: millan
2 Replies

7. UNIX for Dummies Questions & Answers

Storing data from a table into a csv file

Hi I need to write a bash script to take the data stored in 3 oracle tables .. and filter them and store the results in a csv file. It is an Oracle database Thank you (1 Reply)
Discussion started by: ladyAnne
1 Replies

8. Shell Programming and Scripting

Store table contents in csv file

I need to write a script to store the contents of a table in a csv file I'm using Toad, it's a Oracle database. (5 Replies)
Discussion started by: ladyAnne
5 Replies

9. Shell Programming and Scripting

Convert the below file to csv format

Hi , i want to change this question, i will post soon.. (6 Replies)
Discussion started by: srikanth2567
6 Replies

10. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies
Login or Register to Ask a Question