title: "BCP copy in failed" on TSV
body: <p>Note: this is very similar to the question I posted here (<a href="https://stackoverflow.com/q/51937432/8236733">&quot;BCP copy in failed&quot; on tsv (no further error message info)</a>), but I resolved that question with a different solution that does not appear to work in this case. (Title of question similar so that anyone else having these same vague errors can find multiple potential solutions to their problem).</p>
  
  <hr>
  
  <p>Trying to use <code>BCP utility</code> (<a href="https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-2017" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-2017</a>) on linux CentOS7 to copy tsv files into remote MSSQL Server DB (in a Windows Server 2012 machine), getting the frustratingly curt error message that</p>
  
  <blockquote>
    <p>Starting copy...</p>
    
    <p>BCP copy in failed</p>
  </blockquote>
  
  <p>The BCP bash script in question has the form</p>
  
  <pre class="lang-sh prettyprint-override"><code>TO_SERVER_ODBCDSN="-D -S MyMSSQLServer"
  TO_SERVER_IP="-S 172.99.9.29"
  DB="mydb"
  TABLE="mytable" 
  # getting MSSQL Server credentials
  USER=$(tail -n+1 $basedir/src/mssql-creds.txt | head -1)
  PASSWORD=$(tail -n+2 $basedir/src/mssql-creds.txt | head -1)
  DATAFILES="$storagedir/tsv"
  TARGET_GLOB="*.tsv"
  RECOMMEDED_IMPORT_MODE='-c' # see https://stackoverflow.com/a/16310219/8236733
  DELIMITER="\t" # DO NOT use format like "'\t'", nested quotes seem to cause hard-to-catch error
  
  if [[ -z "${TABLE// }" ]]; then
      echo -e "\nNo table specified"
      exit
  fi
  
  {
  echo -e "Truncating destination table: $DB/$TABLE"
  sqlcmd -Q "select count(*) from dbo.$TABLE; truncate table dbo.$TABLE; select count(*) from dbo.$TABLE;" \
      $TO_SERVER_ODBCDSN \
      -U $USER -P $PASSWORD \
      -d $DB
  } || { echo -e "\nFailed to truncate MSSQL DB"; exit 255; }
  
  echo -e "\nConnecting with BCP utility as $USER..."
  
  for filename in $DATAFILES/$TARGET_GLOB; do
  
      if [ ! -f $filename ]; then
          echo -e "\nFile $filename not found!"
      else
          echo -e "\nImporting $filename data to $DB/$TABLE"
      fi
  
      echo -e "Removing header from TSV file $filename"
      echo "$(tail -n +2 $filename)" &gt; $filename
  
      echo -e "Replacing null literal values with empty chars"
      NULL_WITH_TAB="null\t" # WARN: assumes the first field is prime-key so never null
      TAB="\t"
      sed -i -e "s/$NULL_WITH_TAB/$TAB/g" $filename
  
      echo -e "Starting BCP export threads for $filename"
      /opt/mssql-tools/bin/bcp "$TABLE" in "$filename" \
          $TO_SERVER_ODBCDSN \
          -U $USER -P $PASSWORD \
          -d $DB \
          $RECOMMEDED_IMPORT_MODE \
          -t "\t" \
          &amp;
  
  done
  </code></pre>
  
  <p>(providing more than what may be a minimal example here, since I have zero idea why the BCP program is <strong>failing on only certain datasets and working on others</strong>, being that the error message is so vague) and running this produces the output</p>
  
  <pre><code>[me@mapr001 src]$ time ./hdfs2mssql.pq.sh mytable
  
  Truncating destination table: mydb/mytable
  
  -----------
            0
  
  (1 rows affected)
  
  -----------
            0
  
  (1 rows affected)
  
  Connecting with BCP utility as myuser...
  
  Importing /mapr/my.cluster.local//etl/path/to/MYTABLE/tsv/0_0_0.tsv data to mydb/mytable
  Removing header from TSV file /mapr/uceramapr.cluster.local//etl/path/to/MYTABLE/tsv/0_0_0.tsv
  Replacing null literal values with empty chars
  Starting BCP export threads for /mapr/uceramapr.cluster.local//etl/path/to/MYTABLE/tsv/0_0_0.tsv
  
  Starting copy...
  
  BCP copy in failed
  
  
  All export tasks collected and completed
  
  real    0m2.182s
  user    0m0.826s
  sys 0m0.624s
  </code></pre>
  
  <p>From this, it tells some debugging info. </p>
  
  <ol>
  <li>It tells me that <code>sqlcmd</code> is able to actually connect to the remote DB (since able to successfully truncate and get count), ie. unlikely to be a network connection issue. </li>
  <li>Also tells that the problem is (likely) not the same as I had solved in another SO post about BCP being unable to do "in" operation for a TSV file (<a href="https://stackoverflow.com/q/51937432/8236733">&quot;BCP copy in failed&quot; on tsv (no further error message info)</a>), since am already replacing the literal 'null' strings with tabs "\t".</li>
  </ol>
  
  <p>Attempting to inspect the number of tabs for each row in the TSV file via <code>awk '{print gsub(/\t/,"")}' /path/to/0_0_0.tsv</code> appear to show all rows as having 149 tabs. This seems to match up with the 149+1=150 <em>columns</em> in the schema of the remote DB destination table (schema via <code>sp_help &lt;tablename&gt;</code> shown below, sorry if badly formatted):</p>
  
  <pre><code>Column_name Type    Computed    Length  Prec    Scale   Nullable    TrimTrailingBlanks  FixedLenNullInSource    Collation
  PROC_ID float   no  8   53      NULL    yes (n/a)   (n/a)   NULL
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    float   no  8   53      NULL    yes (n/a)   (n/a)   NULL
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    smalldatetime   no  4                   yes (n/a)   (n/a)   NULL
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    nvarchar    no  510                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
  xxxx    smalldatetime   no  4                   yes (n/a)   (n/a)   NULL
  </code></pre>
  
  <p>And here's a mock sample row from the tsv</p>
  
  <pre><code>272647  KXXXX,XXXXSR TRNS&gt;10KILO    31999999                                        19999               57              Y   2   9/1/17 XXX,NO VOL X XXX (XXX XXX XXXX)              Y   999                                             1999    2999                            999         3                       1   1                           Y               2012-05-31 17:41:00         1   KXX,PRXXXX T                                                                                    999                                                                                                     XXXT,PRXXXX TXXX&gt;10KILO                                                                                                                     2018-08-21 14:04:57
  </code></pre>
  
  <p>here with the tab escape characters</p>
  
  <pre><code>272647^IKXXXX,XXXXSR TRNS&gt;10KILO^I31999999^I^I^I^I^I^I^I^I^I^I19999^I^I^I^I57^I^I^I^IY^I2^I9/1/17 XXX,NO VOL X XXX (XXX XXX XXXX)^I^I^I^IY^I999^I^I^I^I^I^I^I^I^I^I^I^I1999^I2999^I^I^I^I^I^I^I999^I^I^I3^I^I^I^I^I^I1^I1^I^I^I^I^I^I^IY^I^I^I^I2012-05-31 17:41:00^I^I^I1^IKXX,PRXXXX T^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I999^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^IXXXT,PRXXXX TXXX&gt;10KILO^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I2018-08-21 14:04:57
  </code></pre>
  
  <hr>
  
  <p>In terms of providing a minimal working example, the code from the script would be </p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  
  filename=$1
  
  # can use ODBC driver...
  TO_SERVER_ODBCDSN="-D -S MyMSSQLServer"
  # ...or host IP
  TO_SERVER_IP="-S &lt;your MSSQL Server IP&gt;"
  DB="mydb"
  TABLE="mytable"
  USER=&lt;your MSSQL Server login&gt;
  PASSWORD=&lt;your MSSQL Server login password&gt;
  DATAFILES=&lt;/path/to/tsv/file(s)&gt;
  TARGET_GLOB="*.tsv"
  RECOMMEDED_IMPORT_MODE='-c' # see https://stackoverflow.com/a/16310219/8236733
  DELIMITER="\t" # DO NOT use format like "'\t'", nested quotes seem to cause hard-to-catch error
  
  echo -e "Removing header from TSV file $filename"
  echo "$(tail -n +2 $filename)" &gt; $filename
  echo "First line of file is now..."    
  echo $(head -n 1 $filename)
  
  echo -e "Replacing null literal values with empty chars"
  NULL_WITH_TAB="null\t" # WARN: assumes the first field is prime-key so never null
  TAB="\t"
  sed -i -e "s/$NULL_WITH_TAB/$TAB/g" $filename
  
  echo -e "Starting BCP export threads for $filename"
  /opt/mssql-tools/bin/bcp "$TABLE" in "$filename" \
      $TO_SERVER_ODBCDSN \
      -U $USER -P $PASSWORD \
      -d $DB \
      $RECOMMEDED_IMPORT_MODE \
      -t "\t" \
  </code></pre>
  
  <p>(where some values must be provided by user, since depends on how systems have setup MSSQL Server and ODBC driver, etc.). However, cannot provide example data for this, since the data I am currently working with is sensitive and I don't know what about the datasets is causing the error (as I said, the script appears to work for some datasets and not for others) in order to produce some mock dataset online that would generate a similar error.</p>
  
  <hr>
  
  <p>Trying this <strong>command with a different table and data-file <em>does</em> work</strong> and at this point the error message is too brief to give me more to debug on (never used BCP utility before). If anyone has experience using this tool, any debugging advice or how to solve this problem would be appreciated.</p>