Results 1 to 8 of 8

Thread: bcp problem

  1. #1
    Join Date
    Apr 2006
    Posts
    6

    Exclamation Unanswered: bcp problem

    Hi.......
    can anyone plz tell me
    how to remove headers of file while bcp in (in Unix )
    e.g.
    name age id
    ---------------------
    abc 18 12

  2. #2
    Join Date
    Jan 2003
    Location
    Geneva, Switzerland
    Posts
    353
    You should be able to use the -F option to skip X rows. So if your file has 2 header rows you can do
    Code:
    bcp foo..the_table in the_table.bcp -U... -P... -S... -c -F 2
    However, I have never tried this.

    Michael

  3. #3
    Join Date
    Apr 2006
    Posts
    6
    Quote Originally Posted by mpeppler
    You should be able to use the -F option to skip X rows. So if your file has 2 header rows you can do
    Code:
    bcp foo..the_table in the_table.bcp -U... -P... -S... -c -F 2
    However, I have never tried this.

    Michael

    ya tht's ok but this for first row---last row
    but if u know ur heder is in first line then ts correct bus suppose u don't know
    how many line ur header have then?
    so is there any option in bcp only which automatically detect header & remove it

  4. #4
    Join Date
    Jan 2003
    Location
    Geneva, Switzerland
    Posts
    353
    No. bcp assumes that the file is entirely composed of the data to be loaded.

    If you need to handle files that may have variable length headers then you will need to find a way to process this outside of bcp (a perl script, for example).

    Michael

  5. #5
    Join Date
    Jul 2006
    Posts
    13
    Use bcp in with same command line you used during bcp out.
    I think unix read file in same way.
    why not use native data format in bcp out/in.
    M. Hassan

  6. #6
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    How do you distinguish between header and data, the ---- ?
    In ksh/bash you can for example use the bcp -F <first_data_row> flag like this
    -F$(($(head thedata.txt| grep -n -- ---- | cut -d: -f1)+1))

  7. #7
    Join Date
    Jul 2006
    Posts
    3
    Quote Originally Posted by bhupendra123
    Hi.......
    can anyone plz tell me
    how to remove headers of file while bcp in (in Unix )
    e.g.
    name age id
    ---------------------
    abc 18 12
    I think you can use -f option with number which indicates no. of rows to be skipped while bcp out. Or you can manually edit the file and remove the lines which you don't need.

  8. #8
    Join Date
    Sep 2002
    Location
    Sydney, Australia
    Posts
    255
    Getting a bit silly ...

    1 Think about how you create the data file in the first place. If you are going to use the file for bcp-in then use bcp-out to create the data file.
    2 If you create the data file using isql, it will be easy to [human] read it, but you will have problems using bcp-in (which are not necessary if you use (1)). In any case, you can use "cut" unix command to remove the headers. The headers are always two lines.

    If you are asking a more generic question (not specific to bcp or isql) re how to find the start-of-data in a file with unspecified header lines, you need another forum.

    Cheers
    Derek Asirvadem
    Senior Sybase DBA/Information Architect derekATsoftwaregemsDOTcomDOTau
    Anything worth doing is worth doing Right The First Time
    Spend your money on standards-compliant development or spend 10 times more fixing it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •