Create Script from table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create Script from table
# 1  
Old 01-11-2012
Create Script from table

I have a table ABC with 4 columns and below data
Code:
Col1,Col2,Col3,Col4
 
prod,10,12,joba
prod,10,11,jobb
qa,10,12,jobc

I want to create an output file like this
Code:
Server:prod
StartTime:10
EndTime:12
JobName:joba
 
Server:prod
StartTime:10
EndTime:11
JobName:jobb
 
Server:qa
StartTime:10
EndTime:12
JobName:jobc

The number of rows can change

Can some one help


Last edited by Scott; 01-11-2012 at 02:42 PM.. Reason: Please use code tags
# 2  
Old 01-11-2012
Code:
nawk -F, -v h='Server,StartTime,EndTime,JobName' 'BEGIN{n=split(h,hA)}{for(i=1;i<=NF;i++) print hA[i],$i;print ""}' OFS=: myFile

# 3  
Old 01-11-2012
Code:
~/unix.com$ awk -F\, 'NR>2{print "Server:"$1"\nStartTime:"$2"\nEndTime:"$3"\nJobName:"$4"\n"}' file

# 4  
Old 01-11-2012
Code:
$ perl -F, -ane '($.<3)&& next;open O,">>out.dat";print O "Server:$F[0]\nStartTime:$F[1]\nEndtime:$F[2]\nJobName:$F[3]\n\n";close O' input
$
$ cat out.dat
Server:prod
StartTime:10
Endtime:12
JobName:joba


Server:prod
StartTime:10
Endtime:11
JobName:jobb


Server:qa
StartTime:10
Endtime:12
JobName:jobc


$
$

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to create the SQLLDR control file from Oracle table.

I need to create the shell script load the few 100 table using the SQLLDR. Need to generate the control file for each table using oracle table. table has "table names" and "column names" using this need create the control file. example table rows below table_nme column_nme DEPT ... (2 Replies)
Discussion started by: pimmit22043
2 Replies

2. Shell Programming and Scripting

Create Pivot table

I would like to use awk to parse a file with three columns in, like: Chennai,01,1 Chennai,07,1 Chennai,08,3 Chennai,09,6 Chennai,10,12 Chennai,11,19 Chennai,12,10 Chennai,13,12 Kerala,09,2 AP,10,1 AP,11,1 Delhi,13,1 Kerala,13,3 Chennai,00,3 Chennai,01,1 Chennai,02,1 Chennai,07,5 (3 Replies)
Discussion started by: boston_nilesh
3 Replies

3. Shell Programming and Scripting

Create DB table through shell script

Hi, Can anyone tell me that, How to create table in Oracle database through shell script(ksh). Table contains 3 fields, 1] Emp ID, String, primary key 2] Name, String 3] B Date, date. Thanks in advance. (6 Replies)
Discussion started by: Poonamol
6 Replies

4. UNIX and Linux Applications

create table via stored procedure (passing the table name to it)

hi there, I am trying to create a stored procedure that i can pass the table name to and it will create a table with that name. but for some reason it creates with what i have defined as the variable name . In the case of the example below it creates a table called 'tname' for example ... (6 Replies)
Discussion started by: rethink
6 Replies

5. UNIX for Dummies Questions & Answers

Create a table - very new to unix

I need to create a simple table of information by grepping several columns from various files and display them all at once with simple headers on top. Can anyone help get me started? I am very new to unix so I really have no idea how to work with this and I appreciate any help I can get! Let me... (11 Replies)
Discussion started by: aj250
11 Replies

6. Shell Programming and Scripting

Create table

Hi I want create table based on csv file .I have come up with some informations getting columns names and then no idea from that .Please any help file.txt col1|col2|col3|col4|col5 1234|zxxxx|xcvvv|300|null file.sh file=$1 c1=`head -1 $file|tr "|" "\n" |cat -n` echo "$c1"... (31 Replies)
Discussion started by: mohan705
31 Replies

7. Shell Programming and Scripting

help with a bash script to create a html table

Hi guys as the title says i need a little help i have partisally written a bash script to create a table in html so if i use ./test 3,3 i get the following output for the third arguement in the script i wish to include content that will be replace the A characters in the... (2 Replies)
Discussion started by: dunryc
2 Replies

8. HP-UX

to create a oracle table in perl script

Hi all, I have to create table for each month inside a perl script. tablename_monthnameyear. megh_aug2008 for august 2008. megh_sep2008 for september 2008. just like the logfiles created on date basis. thanks megh (1 Reply)
Discussion started by: megh
1 Replies

9. Shell Programming and Scripting

create new table/field

Dear Folks, If I have 2 files, say A and B in format: A: $1 $2 01032 12856 01041 13351 01042 11071 01042 12854 01042 12862 01042 12866 . . . and B: (2 Replies)
Discussion started by: Gr4wk
2 Replies
Login or Register to Ask a Question