0

My question is similar to this post but in their example I want to remove the first delimiter in the output. In the SQL file that's being called, I set nocount on, proc_return_status off, and set proc_output_params off which I figured would remove that column previously inhabited by the x rows affected lines and other statements but now it's just blank. For the isql parameters, I'm just using -s"," and am unsure if I need to add anything else.

Desired output:

,some_column_entry,3212

becomes this:

some_column_entry,3212

error when running <code>sed</code> after Temp.out file output.

plankton
  • 395
  • 4
  • 18
  • 1
    run your data through `sed "s/,//"` to remove the first comma (,); alternatively if you know the first comma is always in column one then you could use `cut -c2-` to print all data from column 2 to the end of line – markp-fuso Mar 25 '20 at 20:34
  • @markp-fuso I'm a bit of a beginner with batch files. How exactly would I add those parameters in? I threw them into the end of the line and nothing changed. `isql -w300 -i..\sql\Query_TEST.sql -U %DbUser% -S %DbServer% -P %DbPw% -oOutputFile.csv -s","` – plankton Mar 25 '20 at 20:43
  • 1
    not sure I understand what you mean by 'end of the line' ... I don't see any references to `cut` or `sed` in your comment; also, do you know the first column will always be blank/null? there are several ways to go about stripping the leading comma from `OutputFile.csv` ... one idea ... have your `isql` session send output to `temp.out`, then run `sed "s/^,//" temp.out > OutputFile.csv` (NOTE: I added `^` to ensure only a leading comma is removed); keep in mind your output file will have different column counts if some column 1 values can be non-blank/non-NULL – markp-fuso Mar 25 '20 at 21:05
  • I just mean I put it after the -s parameter like this: `isql -w300 -i..\sql\Query_TEST.sql -U %DbUser% -S %DbServer% -P %DbPw% -oOutputFile.csv -s"," sed "s/,//"` I believe `sed` or `cut` will work as I know the first column will always be null. I tried adding another line into the batch file for the `temp.out` string you provided but it errored out saying "sed is not recognizable as an internal or external command." This is how I typed it: `isql -w300 -i..\sql\Query_TEST.sql.sql -U %DbUser% -S %DbServer% -P %DbPw% -oTemp.out -s","` `sed "s/^,//" temp.out > OutputFile.csv` – plankton Mar 25 '20 at 21:19
  • 1
    your example is generating an error because you're trying to submit `sed ...` as an argument to the `isql` command and that's not doable; what you want to do is run 2 separate commands at the OS prompt: #1 ) `isql -w300 -i..\sql\Query_TEST.sql.sql -U %DbUser% -S %DbServer% -P %DbPw% -oTemp.out -s","` ... then as a separate command: #2) `sed "s/^,//" temp.out > OutputFile.csv` – markp-fuso Mar 25 '20 at 21:24
  • I successfully produce the Temp.out file in the first line but am getting the same error when running the `sed` line separately. I edited the post to add a pic of what I'm doing. Thanks for sticking with me here! – plankton Mar 25 '20 at 21:37
  • 1
    **arg** ... my fault ... I work 99.9% of the time in Unix/Linux environments where `sed` is a standard executable; it looks like you're running `isql` under Windows (dos or power shell?), which doesn't have `sed`; short of getting a unix-like scripting tool (eg, cygwin) installed on your windows machine, we're left with 2x options ... 1) research any dos/powershell commands that can strip the first column/comma from `temp.out` ... or 2) remove the first/always-null column from your `select` which would accomplish the same thing (ie, remove the first column from the output) – markp-fuso Mar 25 '20 at 21:50
  • Ah, got it. Yep I'm in windows. I will have to research dos commands because sadly it's not something I can really control on the query side. At least I don't think, Thanks for your help! – plankton Mar 25 '20 at 21:58

0 Answers0