06-27-2013
To append column names to a table using db2 and shell script
# Get all the columns seperated with comma.
Col_names=$(db2 -x "select colname||',' from syscat.columns where tabname = '$TABLENAME' order by colno")
#Put all the columns in a text file
echo $Col_names > columns.txt
#Export table data to csv which you want to append columns
db2 "EXPORT TO $HOME/$TABLENAME.csv OF DEL MESSAGES $HOME/$TABLENAME.txt select * from $SCHEMA.$TABLENAME"
#Append columns to Table
cat columns.txt $HOME/$TABLENAME.csv > $HOME/newfile.csv
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
How can I use awk to create a new file that has 2 columns, each colums comes form a different file.
example:
I need column 3 from file1 and column 5 from file2 to make file3. (3 Replies)
Discussion started by: cosmologist
3 Replies
2. Shell Programming and Scripting
input1
a_a a/a 10 100
a1 a_a 20 200
b1 b_b 30 300
input2
a_a a/a xxx yyy
a1 a1 lll ppp
b1 b_b kkk ooo
output
a_a a/a 10 100 xxx yyy (2 Replies)
Discussion started by: ruby_sgp
2 Replies
3. Shell Programming and Scripting
Hello Team,
I have written following command which is giving output is as shown below.
bash-3.00$ grep -i startup catalina.out | tail +2 | sed -n 1p | awk -F" " '{ for (x=1; x<=5; x++) { printf"%s\n", $x } }'
Dec
19,
2010
3:28:39
PM
bash-3.00$
I would like to modify above command to... (2 Replies)
Discussion started by: coolguyamy
2 Replies
4. Shell Programming and Scripting
I have a file with contents
"08011"||20080812
"23348"|20080827|20080924
"23387"|20080829|20080915
"23581"|20081003|20081028
"23748"|20081017|20090114
"24095"|20080919|20081013
"24105"|20070723|20070801
"24118"|20080806|20081013
"24165"|20080820|20080912
"24221"|20080908|20080929
i... (3 Replies)
Discussion started by: sonam273
3 Replies
5. Shell Programming and Scripting
Hi Experts,
Please bear with me, i need help
I am learning AWk and stuck up in one issue.
First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique.
Second point : For... (12 Replies)
Discussion started by: as7951
12 Replies
6. Shell Programming and Scripting
Hello,
I have two text tab delimited files
File 1 has 30 columns. I am pasting only first 9
Chr Position Ref Alt Score Gene HGVS_C HGVS_P Coding_Consequence dbSNP
1 17312743 C T 1 Gene1 - ... (2 Replies)
Discussion started by: nans
2 Replies
7. Shell Programming and Scripting
The purpose is to check if values for column 3 and 4 in file1 match with column 1 in file2.
If any value match do:
1) Replace values in file2 for column 2 and 3 using the information of file1 columns 5 and 6
2) Replace string ($1,1,5) and string ($1,6,5) in file2 with values of columns 7... (8 Replies)
Discussion started by: jiam912
8 Replies
8. UNIX for Beginners Questions & Answers
Hi,
I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.)
I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies
9. UNIX for Beginners Questions & Answers
I have 2 files contains more than 5000 lines, I want to paste the 1st column of both file in an output file using awk.
Please suggest to me I had tried paste command but it merges my both column.
--- Post updated at 10:26 PM ---
file1.txt
2020-01-07 235400
2020-01-07 235400
2020-01-07... (4 Replies)
Discussion started by: Sagar Singh
4 Replies
10. UNIX for Beginners Questions & Answers
Hello Everyone,
I have many files like so:
file1.txt
file2.txt
file3.txt
Within each file I have many lines of random text separated by commas like so:
abcAAA,123,defAA,456777,ghiA,789
jklB,101,mnoBBB,11211,pqrB,13111
stuCC,415,vwxCCCC,161,yzaC,718
I am trying to use SED or AWK to... (4 Replies)
Discussion started by: D3U5X
4 Replies
LEARN ABOUT DEBIAN
class::dbi::pg
Class::DBI::Pg(3pm) User Contributed Perl Documentation Class::DBI::Pg(3pm)
NAME
Class::DBI::Pg - Class::DBI extension for Postgres
SYNOPSIS
use strict;
use base qw(Class::DBI::Pg);
__PACKAGE__->set_db(Main => 'dbi:Pg:dbname=dbname', 'user', 'password');
__PACKAGE__->set_up_table('film');
DESCRIPTION
Class::DBI::Pg automate the setup of Class::DBI columns and primary key for Postgres.
select Postgres system catalog and find out all columns, primary key and SERIAL type column.
create table.
CREATE TABLE cd (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT,
artist TEXT,
release_date DATE
);
setup your class.
package CD;
use strict;
use base qw(Class::DBI::Pg);
__PACKAGE__->set_db(Main => 'dbi:Pg:dbname=db', 'user', 'password');
__PACKAGE__->set_up_table('cd');
This is almost the same as the following way.
package CD;
use strict;
use base qw(Class::DBI);
__PACKAGE__->set_db(Main => 'dbi:Pg:dbname=db', 'user', 'password');
__PACKAGE__->table('cd');
__PACKAGE__->columns(Primary => 'id');
__PACKAGE__->columns(All => qw(id title artist release_date));
__PACKAGE__->sequence('cd_id_seq');
METHODS
set_up_table TABLENAME HASHREF
Declares the Class::DBI class specified by TABLENAME. HASHREF can specify options to when setting up the table.
ColumnGroup
You can specify the column group that you want your columns to be in.
$class->set_up_table($table, { ColumnGroup => 'Essential' });
The default is 'All'
Primary
Overrides primary key setting. This can be useful when working with views instead of tables.
pg_version
Returns the postgres version that you are currently using.
AUTHOR
Daisuke Maki "dmaki@cpan.org"
AUTHOR EMERITUS
Sebastian Riedel, "sri@oook.de" IKEBE Tomohiro, "ikebe@edge.co.jp"
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
Class::DBI Class::DBI::mysql DBD::Pg
perl v5.10.1 2006-07-09 Class::DBI::Pg(3pm)