how can I bcp out a table into a text file including the header row in the text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how can I bcp out a table into a text file including the header row in the text file
# 1  
Old 07-21-2009
how can I bcp out a table into a text file including the header row in the text file

Hi All,

I need to BCP out a table into a text file along with the table headers. Normal BCP out command only bulk copies the data, and not the headers.

I am using the following command:
Code:
bcp database1..table1 out file1.dat -c -t\| -b1000 -A8192 -Uuser -Ppassword  -efile.dat.err

Regards,
Shilpa.

Last edited by Yogesh Sawant; 07-21-2009 at 07:26 AM.. Reason: added code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

3. Shell Programming and Scripting

At text to field 1 of header row using awk

I am just trying to insert the word "Index" using awk. The below is close but seems to add the word at the end and I can not get the syntax correct to add from the beginning. Thank you :). awk -F'\t' -v OFS='\t' '{ $-1=$-1 OFS "Index"}$1=$1' file current output Chr Start End ... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. UNIX for Dummies Questions & Answers

Loading text file into table

Hi, I have text file with comma seprater shown below lu8yh,n,Fri,Feb,7,2014,16:5 deer4 deer4,n,Tue,Aug,21,,2012,on r43ed r43ed,n,Tue,Nov,12,2013,12: e43sd e43sd,n,Tue,Jan,1,,2013,on, I am using below code to load the text file into table #!/bin/ksh... (16 Replies)
Discussion started by: stew
16 Replies

5. Shell Programming and Scripting

Select row from file and text

Hi all! I would like to solve a problem but I have no clue of how do it!I will be grateful if someone could help me! Briefly I have a big file like this: >ENSMUSG00000000204 | ENSMUST00000159637 GGCGAGGCTTACGCCATTTTACCTCAGCGAGCATTCATAAAGCTGCGAGCATTCATACAG >ENSMUSG00000000204 |... (3 Replies)
Discussion started by: giuliangiuseppe
3 Replies

6. Shell Programming and Scripting

Make a table from a text file

Hi, I have a pipe separated text file. Can some someone tell me how to convert it to a table? Text File contents. |Activities|Status1|Status2|Status3| ||NA|$io_running2|$io_running3| |Replication Status|NA|$running2|$running3| ||NA|$master2|$master3|... (1 Reply)
Discussion started by: rocky88
1 Replies

7. Shell Programming and Scripting

Put Header on Text file of all column

Hi I have in put file A.txt ABCDE1 JFHFJFJF3 1 1 SC1 12/10 ABCDE2 JFHFJFJF5 1 1 SC1 12/10 ABCDE3 JFHFJFJF5 1 1 SC1 12/10 ABCDE4 JFHFJFJF6 1 1 SC1 12/10 I want output in .csv with header: Name SUb_N x y No Board ABCDE1 JFHFJFJF3 1 1 SC1 12/10 ABCDE2 JFHFJFJF5 1 1 SC1... (7 Replies)
Discussion started by: pareshkp
7 Replies

8. Shell Programming and Scripting

Help in script - Getting table name from a text file

hhhhhhhhhh (5 Replies)
Discussion started by: sams
5 Replies

9. Shell Programming and Scripting

Convert Header into Column in Text file

Hi Gurus, I have a requirement like this and have to create a UX shell scripts. Thanks in advance. File-in: ------ Header2007-12-012007-11-21 100|xyz|was 101|wsa|qws ...... ....... Output should be: ------------------- 2007-12-01|100|xyz|was 2007-12-01|101|wsa|qws ...... .......... (7 Replies)
Discussion started by: vsubbu1000
7 Replies

10. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies
Login or Register to Ask a Question
freebcp(1)							 FreeTDS Utilities							freebcp(1)

NAME
freebcp - bulk loading utility for Sybase and Microsoft databases SYNOPSIS
freebcp [[database.]owner.]object_name {in | [query]out} datafile { -c | -n | -f formatfile } [-b batchsize] [-F firstrow] [-L lastrow] [-e errfile] [-I interfaces] [-m maxerrors] [-t field_term] [-r row_term] [-h hints] [-T textsize] [-A packet_size] [-O options] [-S servername] [-U username] [-P password] [-EdVv] DESCRIPTION
freebcp is a utility program distributed with FreeTDS. freebcp replicates (in part at least) the functionality of the "bcp" utility pro- grams distributed by Sybase and Microsoft. freebcp makes use of the db-lib bcp API provided by FreeTDS. This API is also available to application developers. The manual pages or online help for Sybase or SQL Server can be referenced for more detailed information on "bcp" functionality. TABLES AND FILES
database The database of the object being copied. Optional if the table/view is in the default database for username. owner The owner of the object being copied. Optional if username or the database owner is the owner of the table. object_name Usually, object_name is the name of the database table you wish to access. It can also be a view (and, subject to constraints, it is sometimes possible to load a view). It can also be an SQL query, cf. queryout, below. in | [query]out The direction of the bulk copy operation. 'in' indicates data are to be copied from a host file into a database table; 'out' indi- cates data are to be copied from a database table to a host file. 'queryout' indicates that table_name is in fact a query, rather than a database object. freebcp will execute the query and write the results to a file. (It is a good idea to have the query return one and only one result set.) datafile The name of an operating system file. OPTIONS
-c The host data file is (or will be) in "character" format, i.e., a text file. Encoding is determined by the client charset attribute in freetds.conf. -n The host data file is in "native" format. This is a format that freebcp will be able to process, but is not portable or readable. -f formatfile The format of the host data file is described by formatfile. The layout of formatfile is identical to that understood by the Sybase and Microsoft bcp utilities, but is too complicated to describe here. -b batchsize The number of rows per batch of data copied. Batching applies only when you are bulk copying into the database. Each batch of data is effectively 'committed' into the database. The default value for batchsize is 1000. -F firstrow The first row to copy from the input file or database table. The default is the first row, row 1. -L lastrow The last row to copy from an input file or database table. The default is the last row. -r row_term The row terminator for a character file. May be more than one character. Default is newline (' '). Cf. -c, above. -t field_term The field terminator for character file. Also known as a column delimiter. May be more than one character. Default is tab (' '). Cf. -c, above. -m maxerrors Stop after encountering maxerror errors. Default 10. -e errfile Write errors to error_file. For uploads. Includes line and column information, and the row data. -S servername The name of the Database Server to which to connect. -U username A database login name. If username is not provided, a domain login is attempted for TDS 7+ connections. -P password A database password. -E Write the data in datafile to the table's IDENTITY column. Without this flag, the identity data present in the datafile will be ignored, and new IDENTITY values will be generated for the imported rows. -d Turn off any logging. (Unintuitive, perhaps.) -O options SQL text to set connection options prior to the bcp operation. If options is a valid filename, the SQL is read from the file instead. Sometimes needed for queryout. Example: "-O 'SET QUOTED_IDENTIFIER ON'" -I interfaces The name and location of the interfaces file to search when connecting to servername. Overrides freetds.conf. -h hints Set bcp hints. For valid values, cf. bcp_options() in the FreeTDS Reference Manual. -T textsize For text or image columns, set the maximum number of characters to request from the server. Defaults to the setting in freetds.conf. If not specified anywhere, defaults to the full size of the data. -A packet_size Set the size of a TDS packet to packet_size. Not sure why you would want to do this, except as an experiment. -v -V Print the version information and exit. ENVIRONMENT
DSQUERY default servername NOTES
When connecting to a Sybase database server, it is required that the TDS 5.0 protocol be used. When connecting to a Microsoft SQL Server 2000 database server, the TDS 7.1 protocol is required. Theoretically both Sybase and Microsoft support the TDS 4.2 protocol, but in reality they implement the bcp portion of TDS 4.2 differently. FreeTDS has no way of knowing which type of server it's connected to, hence TDS protocol 4.2 is not supported. HISTORY
freebcp first appeared in FreeTDS 0.60 AUTHORS
The freebcp utility was written by Bill Thompson (thompbil@exchange.uk.ml.com) BUGS
Currently, there is no support for text data types in freebcp, when SQL Server 2000 is the target database. doc 13 November 2011 freebcp(1)