Script to create a CSV file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to create a CSV file
# 1  
Old 05-21-2013
Script to create a CSV file

I created a script that will go out and so a "/sbin/chkconfig --list | egrep XXX" against a server list that would create an output file like the following example:

Code:
----------------------------------------------------------------------------------
SERVER1
RC_Script_1      0:off   1:off   2:off   3:on    4:off   5:off   6:off
RC_Script_2      0:off   1:off   2:off   3:on    4:off   5:off   6:off
Connection to SERVER1 closed.

----------------------------------------------------------------------------------
SERVER2
RC_Script_1      0:off   1:off   2:off   3:on    4:off   5:off   6:off
Connection to SERVER2 closed.

----------------------------------------------------------------------------------

I would like to create a CSV file so that when I open it I would have something like:

SERVER1, RC_Script_1, etc
SERVER2, RC_Script_1, etc

One problem is a server might have no RC Script(s), Three, or more...
# 2  
Old 05-22-2013
Try this

Code:
 your_script | awk '/^-/ { getline; S=$1 ; next }
S && /Connection/ {S=0}
S {print S","$1", etc" }'

# 3  
Old 05-22-2013
Quote:
Originally Posted by Chubler_XL
Try this

Code:
 your_script | awk '/^-/ { getline; S=$1 ; next }
S && /Connection/ {S=0}
S {print S","$1", etc" }'

That did not seem to work Smilie

In my script I have
Code:
done | tee -a ${logfile}

at the end. I tried running the above after commenting out the logfile. I get the following back:

Code:
,, etc862
,RC_Script1, etc
,RC_Script2, etcSERVER1
,RC_Script3, etcs863
                     Connection to SERVER1 closed.
,, etc863
,RC_Script1, etc
Connection to SERVER2 closed.
,RC_Script2, etc
,, etc866
,RC_Script, etc
,RC_Script1, etcSERVER3
,was-appservers, etcSERVER3
,was-dmgr, etc      SERVER3
,RC_Script2, etcSERVER3
,was-nodeagent, etcSERVER3
,RC_Script3, etcSERVER3
                     Connection to SERVER3 closed.

# 4  
Old 05-22-2013
Looks like the output doesn't match what you have in post #1.

Of particular importance is the line of dash ("-") characters starting a column 1
# 5  
Old 06-10-2013
I double checked and this is a part of the output file:

Code:
SERVER1
RC_Script_1	0:off   1:off   2:off   3:on    4:off   5:off   6:off

----------------------------------------------------------------------------------
SERVER2
RC_Script_1	0:off   1:off   2:off   3:on    4:off   5:off   6:off

----------------------------------------------------------------------------------
SERVER3
RC_Script_1	0:off   1:off   2:off   3:on    4:off   5:off   6:off

----------------------------------------------------------------------------------
SERVER4
RC_Script_1	0:off   1:off   2:on    3:on    4:off   5:on    6:off
RC_Script_2	0:off   1:off   2:on    3:on    4:off   5:on    6:off

----------------------------------------------------------------------------------
SERVER5
RC_Script_1	0:off   1:off   2:on    3:on    4:off   5:on    6:off
RC_Script_2	0:off   1:off   2:on    3:on    4:off   5:on    6:off

----------------------------------------------------------------------------------
SERVER6
RC_Script_1	0:off   1:off   2:off   3:on    4:off   5:off   6:off

----------------------------------------------------------------------------------

Would it be easier if I had the server name on each line ?

EX:
Code:
SERVER1	RC_Script_1	0:off   1:off   2:off   3:on    4:off   5:off   6:off

----------------------------------------------------------------------------------
SERVER2	RC_Script_1	0:off   1:off   2:off   3:on    4:off   5:off   6:off

----------------------------------------------------------------------------------
SERVER3	RC_Script_1	0:off   1:off   2:off   3:on    4:off   5:off   6:off

----------------------------------------------------------------------------------
SERVER4	RC_Script_1	0:off   1:off   2:on    3:on    4:off   5:on    6:off
SERVER4	RC_Script_2	0:off   1:off   2:on    3:on    4:off   5:on    6:off

----------------------------------------------------------------------------------
SERVER5	RC_Script_1	0:off   1:off   2:on    3:on    4:off   5:on    6:off
SERVER5	RC_Script_2	0:off   1:off   2:on    3:on    4:off   5:on    6:off

----------------------------------------------------------------------------------
SERVER6	RC_Script_1	0:off   1:off   2:off   3:on    4:off   5:off   6:off

----------------------------------------------------------------------------------


Last edited by asnatlas; 06-10-2013 at 05:21 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk and sed script to create one output CSV file

Hi All , I would require your help to generate one output file after post processing of one CSV file as stated below This file is just a small cut from a big file . Big file is having 20000 lines PATTERN,pat0,pat1,pat2,pat3,pat4,pat5,pat6,pat7,pat8,pat9... (2 Replies)
Discussion started by: kshitij
2 Replies

2. Shell Programming and Scripting

Create csv from text file

Gents, I am trying to create a csv file using the file attached. I have a problem to get all information required because the rows are not continues. Here is my code till now. awk ' /"ffid"/{if(s){print s;s=$NF}else{s=$NF}} /"LineNumber"/{s=s $NF} /"PointNumber"/{s=s $NF}... (4 Replies)
Discussion started by: jiam912
4 Replies

3. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

4. UNIX for Dummies Questions & Answers

How to Create excel file(.csv) using shell script?

Hi, i have shell script which compiles n number of test cases and execute them one by one. i want to create report in excel through script in which two columns namely "test id" and "release".second column have two subcolumns namely compiles and excutes. so i want first column should display test... (15 Replies)
Discussion started by: RamMore123
15 Replies

5. Shell Programming and Scripting

Need help. How to create csv file?

Hi I'm a beginner and I have some problem. I have multiple files in the same directory which has one column but rows following the format. File: directory/Disk.txt Content: a b c d e File: directory/Memory.txt a b c d e File: directory/CPU.txt (3 Replies)
Discussion started by: thenuie
3 Replies

6. Shell Programming and Scripting

How to create multiline csv cell through shell script?

Hi, I have a text like the one given below status="Observation 1" read1="Source rows not load" read2="Score drop" I want to create a csv and mail it out in such a way that all three lines will be in a single cell but as three lines. For ex Col C1 ... (3 Replies)
Discussion started by: prasperl
3 Replies

7. Shell Programming and Scripting

Create an .csv/excel file using shellscript

In my file, i have 4 Product names(For ex:Microsoft excel, Oracle,.Net,IBM websphere,..etc.,) I want this 4 Products in 4 individual .csv/excel file after running the script with those products related information. (12 Replies)
Discussion started by: Navya
12 Replies

8. Shell Programming and Scripting

ksh script to create a generic csv file from different source formats

Hi all, I have a requirement to create a "superset" file out of a number of different sources with some different and some same columns. We intend to have a manually updateable SuperSetCols.csv which would look like "ColA","ColB","ColC","ColD","ColE","ColF","ColG" so someday we may add... (3 Replies)
Discussion started by: Leedor
3 Replies

9. Shell Programming and Scripting

Help to create script which reade values from csv

I have a csv file :-my csv file has say 10 columns eg:- A,1,2,3,4,5,6,7,8,9 B,1,2,3,5,6,7,8,9 c,1,2,6,7,8,9 ----------------- I have to create a flat file from this file .The condition is each columns has fixed lenght declared: say length of column 1 = 1 length of column 2 =3 ... (1 Reply)
Discussion started by: Sanal
1 Replies

10. Shell Programming and Scripting

how to create csv file using shell script

I have a file in multiple directory which has some records in the following format File: a/latest.txt , b/latest.txt, c/latest.txt -> Name=Jhon Age=27 Gender=M Street=LA Road Occupation=Service I want to generate a csv file from the above file as follows File: output.csv -> ... (9 Replies)
Discussion started by: rjk2504
9 Replies
Login or Register to Ask a Question