Question

How do i remove the header underline from a file generated by SQLCMD in a batch file? I am trying to automate a process that puts a file in a directory to be processed by another app and it chokes on the dashed line under the header Example:

1. Header1 Header2 header3 header4
2. ------  ------  ------  ------ 
3. Data1   Data2   Data3   Data4 
4. Data1   Data2   Data3   Data4 
5. Data1   Data2   Data3   Data4 
6. Data1   Data2   Data3   Data4 

I need to remove line 2. so the other app does not choke on it. The app needs the Headers but dies on the dashed line below it.

Was it helpful?

Solution

JerryG posted:

I found an answer on another site that worked. I used an -h-1 in the SQLCMD call to turn off Headers and then in the sql before the Select that built my file i put a Print 'Header1 Header2 etc.' with the HeaderX being the actual Column name and the tab between each header as the file output is Tab delimited. It worked and the file uploaded Thanks – JerryG

OTHER TIPS

You could use find or findstr to filter out unwanted lines, eg.:
findstr /v /c:"------ ------ ------ ------" your_filename

and then redirect the output to file or feed/pipe it directly to your app (if it accepts input from stdin)

Using sqlcmd, you can simply add right after the sqlcmd command, the addition:

|findstr /v /c:"-"

Like:

>sqlcmd -E -S <server> -Q "set nocount on;select Header1,Header2,header3,header4 from myTable"|findstr /v /c:"-"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top