I'm creating a batch file to run a stored procedure and write my result into CSV from a table in Google BigQuery. My batch file script is like this:
set target_dir=C:\Temp\
call bq query --use_legacy_sql=false "call mydataset.sp_test()"
bq query --format=csv --max_rows=3000000 --use_legacy_sql=false ^
"select * from mydataset.test" > %target_dir%TEST_%date:~6,4%%date:~3,2%%date:~0,2%.csv
The default delimiter of my .csv file is a comma ,
how can I change the delimiter to a pipeline | or other specified delimiter in my batch file script?
Related
What is the command line option to bcp out a table into a file in the PC/IXF format so that it can be read by another DBMS(db2)
Or, how to convert a bcp out .txt file to a PC/IXF file format
Story: I have a bat file being run weekly that generates a CSV file dump based on a query.
I would like to separate the file in two based on a value in a column. That column is a flag with binary values (0,1)
Objective: My goal is to create two CSV files where the content is based on this:
CSV 1:
select *
from table
where flag = 0
CSV 2:
select *
from table
where flag = 1
My current bat file looks like this:
How can I modify it without having to create two SQL query files because they're pretty huge.
sqlcmd -S ServerName -i "pathOfSqlQuery" -s , -W -u |findstr /v /c:"---" > "DestinationFilename.csv"
If you have SSIS available on the server, I would use an SSIS job. Create a job with the query as your data source and in the next step do a conditional split into each file based on your criteria. You can take the exact columns you want into each file (for instance you can exclude the flag column if you don't need it) and the query is only run once. This can be scheduled using SQL Agent.
There's a bit of learning to SSIS but the control and flexibility you gain will be worth it.
I'm trying to get the classpath with maven to a file, using the command:
mvn dependency:build-classpath -Dmdep.ouputFile=test.txt
but the result is in one line separated with ';'.
The problem is when I try to read the line with windows batch I'm not getting results because the line is larger than 8192 characters.
can I get the results in multiple lines instead of one?
If there is a way to use /P as #Squashman suggested but getting the parts based on the delimiter it will be great, otherwise, I prefer to get the dependencies list as multiple lines by the maven command if there is any.
Splitting up the long line in file test.txt is an easy to achieve task with using JREPL.BAT written by Dave Benham which is a batch file / JScript hybrid to run a regular expression replace on a file using JScript.
Download the ZIP file containing JREPL.BAT and extract this batch file into directory of your batch file. Add to your batch file the following lines to replace all semicolons in test.txt by carriage return + line-feed.
call "%~dp0jrepl.bat" ";" "\r\n" /XSEQ /F test.txt /O -
So i am converting excel files into a .txt files using vbs, and the input file name needs to be the same as the output file name with the changed file extension obviously. Whats making this so hard is the fact that I using this as basically a file converter so the names of the files will be random.
The way I load the input file is by is using the %1 command and just pass in the input file after I call the batch like this.NOTE: the .xlsx can be changed to any .xlsx file that i need to convert.
C:\tabdim>conversion_batch_file.bat **C:\tabdim\2160707.xlsx**
In the batch file (C:\tabdim\conversion_batch_file.bat) Note: the rest of the sql has been replaced with x's.
%windir%\SysWow64\wscript.exe C:\tabdim\combined.vbs **%1**
sqlcmd - xxxxxxxxxxxxxxxxxxxx
bcp xxxxxxxxxxxxxxxx "**C:\tabdim\20160707.txt**" xxxxxxxxxxxxxx
sqlcmd - xxxxxxxxxxxxxxxxxxxx
If there was any way to do something like this
"%1- last 4 characters+".txt""
I know that is totally wrong syntax, I'm just kind of using words to describe kind of what I'm trying to have happen.
I have a file which has the below content. this is diff list between two tags
type files.txt
A demo.bat
M tmp1.bat
M tmp2.bat
D test1.bat
here I need only A(addition) and m(modified) files. D(deleted) files should be ignored. How to grep only these files in windows batch. after that I need to get last column which is file names. now we will have only file names. these files are located in the same folder. Now we need to run the scripts one by one by using timestamp. I need to run only modified\created scripts by timestamp. Can someone tell me how to do this using windows batch script?
To get the file names in the file which has A or M in the first column.
$ awk '$1~/^(A|M)$/{print $2}' files.txt
demo.bat
tmp1.bat
tmp2.bat