BCP Command Line and CSV Format File Output - command-line

This is my bcp command line:
bcp "exec DB.dbo.StoredProcedure" queryout (path to output file) -f (path to format file) -T -S<host>
This is my bcp format file to output a CSV file.
10.0
20
1 SQLINT 0 10 "\t" 1 Id ""
2 SQLNVARCHAR 0 255 "\t" 2 Name SQL_Latin1_General_CP1_CI_AS
3 SQLNVARCHAR 0 255 "\t" 3 Corporation SQL_Latin1_General_CP1_CI_AS
4 SQLNVARCHAR 0 255 "\t" 4 Address1 SQL_Latin1_General_CP1_CI_AS
5 SQLNVARCHAR 0 255 "\t" 5 Address2 SQL_Latin1_General_CP1_CI_AS
6 SQLNVARCHAR 0 255 "\t" 6 City SQL_Latin1_General_CP1_CI_AS
7 SQLNVARCHAR 0 255 "\t" 7 State SQL_Latin1_General_CP1_CI_AS
8 SQLNVARCHAR 0 255 "\t" 8 ZipCode SQL_Latin1_General_CP1_CI_AS
9 SQLNVARCHAR 0 255 "\t" 9 County SQL_Latin1_General_CP1_CI_AS
10 SQLNVARCHAR 0 255 "\t" 10 Phone SQL_Latin1_General_CP1_CI_AS
11 SQLNVARCHAR 0 255 "\t" 11 Latitude SQL_Latin1_General_CP1_CI_AS
12 SQLNVARCHAR 0 255 "\t" 12 Longitude SQL_Latin1_General_CP1_CI_AS
13 SQLNVARCHAR 0 255 "\t" 13 Area SQL_Latin1_General_CP1_CI_AS
14 SQLNVARCHAR 0 255 "\t" 14 Region SQL_Latin1_General_CP1_CI_AS
15 SQLNVARCHAR 0 255 "\t" 15 Email SQL_Latin1_General_CP1_CI_AS
16 SQLNVARCHAR 0 255 "\t" 16 LevelOfCare SQL_Latin1_General_CP1_CI_AS
17 SQLNVARCHAR 0 255 "\t" 17 Description SQL_Latin1_General_CP1_CI_AS
18 SQLNVARCHAR 0 255 "\t" 18 Options SQL_Latin1_General_CP1_CI_AS
19 SQLNVARCHAR 0 255 "\t" 19 Rates SQL_Latin1_General_CP1_CI_AS
20 SQLNVARCHAR 0 255 "\r\n" 20 Photos SQL_Latin1_General_CP1_CI_AS
The output is not getting delimited and it's all over the place. Does anyone know what I'm doing wrong? I can't use comma as a delimiter due the content being output.

Related

How do I chart categorical, cumulative, and time-dependent data?

I have a bunch of time-dependent data, non-decreasing and right-continuous, always with come category involved, that can be repeated. I am looking for a sort of a variable width-bar chart, or cascade chart, flipped on it's side, from the right. For example,
set term postscript eps enhanced
set output "so.eps"
$Data <<EOD
# date source reg sic pic total
2000-07-25 2000glider C-FJSN 8 0 216
2000-07-28 2000glider C-FJSN 10 0 226
2000-07-28 2000glider C-FJSN 11 0 237
2000-07-28 2000glider C-GCLB 4 0 241
2000-07-29 2000glider C-GCLY 3 0 244
2000-07-29 2000glider C-GCLY 2 0 246
2000-07-29 2000glider C-GCLY 17 0 263
2000-07-30 2000glider C-GCLB 15 0 278
2000-07-30 2000glider C-GCLB 0 13 291
2000-07-30 2000glider C-GCLK 11 0 302
2000-07-30 2000glider C-FJSN 0 16 318
2000-07-30 2000glider C-GCLB 0 10 328
2000-08-02 2000glider C-GQRT 0 13 341
2000-08-04 2000glider C-GCLY 0 11 352
2000-08-05 2000glider C-GCLB 12 0 364
2000-08-05 2000glider C-GCLB 0 12 376
2000-08-06 2000glider C-GCLB 0 11 387
2000-08-07 2000glider C-GFMB 0 12 399
2000-08-07 2000glider C-GCMB 0 11 410
2000-08-08 2000glider C-GCLK 0 12 422
2000-08-09 2000glider C-GCLB 14 0 436
2000-08-09 2000glider C-GCLB 0 9 445
2000-08-10 2000glider C-GCLL 0 10 455
EOD
set monochrome
set xdata time
set timefmt "%Y-%m-%d"
set xtics format "%Y-%m-%d" rotate by -30
set ylabel "hours"
set grid
unset key
unset border
plot $Data using 1:($6/60) with fillsteps lw 2, \
$Data using 1:($6/60):3 with labels
Which gives,
I'm trying to create like a cumulative distribution function, where hours, in this case, are added. I want the line to go to zero on the left and the maximum value on the right. The labels, instead of printing, should be in the key and mapped to the data, grouped with other consecutive data, from the right. Is there such a plot, and how to I create it?
I have full control over the input, so I was thinking maybe an inverse-transform and rotate would be easier?
Not sure if I fully understood all your points correctly.
Maybe the following script might bring you closer to what you want.
Update:
If you want color bars for intervals then you could use the plotting style with boxxyerror (check help boxxy).
with boxxy requires either 4 or 6 columns. 4 columns would be (x):(y):(dx):(dy) for a box centered at x,y with +/-dx and +/-dy.
sum up your durations which are either in column 4 or 5 in the variable total. No need for column 6.
the difference dx=43200 (i.e. half a day in seconds)
There are different ways of plottings steps.
Script:
### cumulative plot with color code
reset session
$Data <<EOD
# date source reg sic pic total
2000-07-25 2000glider C-FJSN 8 0 216
2000-07-28 2000glider C-FJSN 10 0 226
2000-07-28 2000glider C-FJSN 11 0 237
2000-07-28 2000glider C-GCLB 4 0 241
2000-07-29 2000glider C-GCLY 3 0 244
2000-07-29 2000glider C-GCLY 2 0 246
2000-07-29 2000glider C-GCLY 17 0 263
2000-07-30 2000glider C-GCLB 15 0 278
2000-07-30 2000glider C-GCLB 0 13 291
2000-07-30 2000glider C-GCLK 11 0 302
2000-07-30 2000glider C-FJSN 0 16 318
2000-07-30 2000glider C-GCLB 0 10 328
2000-08-02 2000glider C-GQRT 0 13 341
2000-08-04 2000glider C-GCLY 0 11 352
2000-08-05 2000glider C-GCLB 12 0 364
2000-08-05 2000glider C-GCLB 0 12 376
2000-08-06 2000glider C-GCLB 0 11 387
2000-08-07 2000glider C-GFMB 0 12 399
2000-08-07 2000glider C-GCMB 0 11 410
2000-08-08 2000glider C-GCLK 0 12 422
2000-08-09 2000glider C-GCLB 14 0 436
2000-08-09 2000glider C-GCLB 0 9 445
2000-08-10 2000glider C-GCLL 0 10 455
EOD
# get a unique list from datablock
addToList(list,col) = list.( strstrt(list,'"'.strcol(col).'"') > 0 ? \
'' : ' "'.strcol(col).'"')
Uniqs = ''
stats $Data u (Uniqs=addToList(Uniqs,3)) nooutput
Uniq(i) = word(Uniqs,i)
getIndex(s) = sum [_i=1:words(Uniqs)] s eq word(Uniqs,_i) ? _i : 0
myTimeFmt = "%Y-%m-%d"
set format x myTimeFmt timedate
set xtics format myTimeFmt rotate by -30
set ylabel "hours"
set format y "%tH:%tM" timedate
set grid
set key out reverse Left noautotitle
set style fill solid 0.5
plot total=0 $Data u (timecolumn(1,myTimeFmt)):(dy=($4+$5)*60,total=total+dy) w steps lc "black" dt 3, \
total=0 '' u (timecolumn(1,myTimeFmt)):(dy=($4+$5)*60,total=total+dy,total-dy/2.): \
(43200):(dy/2.):(getIndex(strcol(3))) w boxxy lc var, \
for [i=1:words(Uniqs)] keyentry w boxxy lc i ti Uniq(i)
### end of script
Result:

Split row according to last column values and save them into different files

I have a txt file which have 9 column and the last column is either 0 or 1. I want to save them into different txt file based on the value of last column.How do I do this using matlab?
txt file
43 34 6 8 2 6 2 3 0
23 54 2 5 8 2 61 6 1
46 4 6 8 23 6 2 3 0
3 5 2 75 48 23 1 6 0
3 54 23 5 58 2 1 6 1
46 4 67 8 3 6 24 23 0
32 5 2 75 98 23 1 6 1
I assume you know how to save matrix to files but not the way to split the matrix.
Here I just provide a solution that can help you split the matrix according to the last column:
% ending with 0 in each row
m0 = m(find(m(:,end)==0),:);
>> m0
m0 =
43 34 6 8 2 6 2 3 0
46 4 6 8 23 6 2 3 0
3 5 2 75 48 23 1 6 0
46 4 67 8 3 6 24 23 0
% ending with 1 in each row
m1 = m(find(m(:,end)),:);
>> m1
m1 =
23 54 2 5 8 2 61 6 1
3 54 23 5 58 2 1 6 1
32 5 2 75 98 23 1 6 1
then you can save the matrices m0 and m1 in different .txt files, e.g., dlmwrite('m0.txt',m0) and dlmwrite('m1.txt',m1)
DATA
m = [43 34 6 8 2 6 2 3 0
23 54 2 5 8 2 61 6 1
46 4 6 8 23 6 2 3 0
3 5 2 75 48 23 1 6 0
3 54 23 5 58 2 1 6 1
46 4 67 8 3 6 24 23 0
32 5 2 75 98 23 1 6 1];

Triangular Multiplication Table

I'm working on a program that's supposed to write out the multiplication table as shown in the picture.
This is what I've done
A = (1:10)'*(1:10);
tril (A)
And this is my output. Is there a way I can do this without the zeros?
Or should I go with a different approach? Any help is greatly appreciated.
1 0 0 0 0 0 0 0 0 0
2 4 0 0 0 0 0 0 0 0
3 6 9 0 0 0 0 0 0 0
4 8 12 16 0 0 0 0 0 0
5 10 15 20 25 0 0 0 0 0
6 12 18 24 30 36 0 0 0 0
7 14 21 28 35 42 49 0 0 0
8 16 24 32 40 48 56 64 0 0
9 18 27 36 45 54 63 72 81 0
10 20 30 40 50 60 70 80 90 100
Here's one way:
A=tril((1:10)'*(1:10))
A(A==0)=NaN;
S=num2str(A);
S(S==78|S==97)=' '
The second line distinguishes plain old '0' from a pesky '0' in, say, '20'.
The third line converts the array to a string.
The last line replaces capital 'N' (character 78) and lowercase 'a' (character 97) with blank space.
Your approach is good, but if you want to avoid the zeros you want strings, not numbers. For example,
>> n = 10;
>> char(arrayfun(#(k) {sprintf('%i ', k:k:k^2)}, 1:n).')
ans =
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
10 20 30 40 50 60 70 80 90 100
How it works
sprintf('%i ', k:k:k^2) generates each row of the table as a string. cellfun is used to iterate over all rows. The rows are packed into a cell array of strings, and that cell array is converted to a char matrix, which automatically pads with spaces.

Stacked-area with date format at x-axis on Gnuplot

I have created graphs using filledcurves. Now, the graphs looks bad because long range of data.
This is my data:
a b c d e f g h i
201312 49 26 34 30 14 25 9 4 1
201311 38 22 47 30 9 9 4 3 1
201310 44 24 43 38 9 14 5 7 0
201309 65 18 33 39 15 12 4 5 1
201308 42 31 44 30 5 11 0 2 2
201307 58 27 35 29 8 4 2 4 2
201306 30 22 15 17 2 6 3 4 0
201305 61 52 20 16 11 12 2 3 0
201304 62 60 33 18 13 9 5 6 0
201303 43 53 49 27 9 11 7 0 0
201302 31 30 42 27 10 8 4 2 0
201301 42 30 20 47 9 13 3 2 1
201212 26 19 39 24 9 11 0 0 0
201211 26 26 30 28 1 2 0 2 1
201210 55 46 34 30 13 5 0 2 1
201209 56 31 27 28 27 13 2 4 1
201208 48 75 38 46 22 10 0 1 0
201207 60 56 37 47 19 11 2 1 0
201206 60 41 37 28 17 12 5 1 0
201205 49 43 38 46 15 16 2 2 0
201204 43 50 36 33 4 7 3 0 2
201203 49 63 35 43 16 7 1 2 0
201202 43 59 59 52 16 13 3 4 1
201201 51 44 30 37 20 9 4 1 0
201112 50 38 36 36 8 2 3 1 1
201111 75 35 30 36 16 7 3 3 1
201110 68 53 41 27 11 15 1 2 1
201109 68 46 48 47 16 19 4 0 1
201108 45 41 20 36 17 10 1 0 0
201107 48 34 30 24 13 7 3 3 1
201106 49 29 24 25 5 6 0 3 0
201105 45 35 21 37 1 7 2 1 0
201104 53 35 23 18 4 6 1 5 1
201103 58 42 20 18 6 4 1 0 4
201102 54 32 19 20 4 10 0 2 0
201101 42 41 21 28 3 6 1 2 1
and this is my gnuplot file:
set terminal postscript eps color font 20
set xtics 1 out
set tics front
#set style fill transparent solid 0.5 noborder
set key below autotitle columnheader
set ylabel "Count"
set xlabel "across time"
set output 't1.eps'
set title "t1-Across time of Aspects"
set xtics 1
plot for [i=10:2:-1] \
"< awk 'NR==1 {print \"year\",$".(i-1)."} NR>=2 {for (i=2; i<=".i."; i++) \
{sum+= $i} {print $1, sum; sum=0} }' data.dat" \
using (column(2)):xtic(1) with filledcurves x1 t column(2)
When I add time in xdata:
set xdata time
set timefmt "%Y%m"
set xtics format "%b"
Erros message:
Need full using spec for x time data
Is the Errors because of my date format? I have googling this and do not have any answer about it. Please give me suggestion about this.
In the script you show, you specify only a single column in the using statement (besides the xtic). That means, that this value is taken as y-value and the row number is implicitely used as x-value.
When using time data, you must explicitely specify all columns which are needed for the plotting style, there is no assumption about what might be the first column. Use:
set key below autotitle columnheader
set ylabel "Count"
set xlabel "across time"
set tics front
set xdata time
set timefmt "%Y%m"
set xtics format "%b'%y"
set autoscale xfix
plot for [i=10:2:-1] \
"< awk 'NR==1 {print \"year\",$".(i-1)."} NR>=2 {for (i=2; i<=".i."; i++) \
{sum+= $i} {print $1, sum; sum=0} }' data.dat" \
using 1:2 with filledcurves x1 t column(2)
Result with 4.6.4:
I guess you don't want xtic(1) if you have time data and specify the x format.

Group the results of grep command

I've been using grep -f to obtain patterns from one file and extract lines from the other.
The results are like below:
1 11294199 11294322 40 10 123 0.0813008
1 11294199 11294322 41 6 123 0.0487805
1 11294199 11294322 42 10 123 0.0813008
1 11294199 11294322 43 2 123 0.0162602
1 11293454 11293544 51 1 90 0.0111111
1 11293454 11293544 52 2 90 0.0222222
1 11291356 11291491 54 6 135 0.0444444
1 11291356 11291491 55 8 135 0.0592593
1 11291356 11291491 56 3 135 0.0222222
Now I need to group the results based on the first three columns,and calculate the sum of column 4 for each of the groups:
1 11294199 11294322 (40+41+42+43)
1 11293454 11293544 (51+52)
1 11291356 11291491 (54+55+56)
How can I get such results? Any options in grep to achieve this?
thx
You will need awk to do what you want. Try this:
awk '{ array[$1 "\t" $2 "\t" $3] += $4 } END { for (i in array) print i "\t" array[i] }' file.txt
Results:
1 11294199 11294322 166
1 11291356 11291491 165
1 11293454 11293544 103
HTH