Removing White Spaces from SQLCMD output - sqlcmd

USing SQLCMD on SQL version 2016...to remove white spaces from my output, I've tried the -W -s switches...and I still get white spaces....Here's my code
SQLCMD -S myserver -d mydb -b -Q "exec dbo.GetiBottaItemFile"
-o "myfile" -W -s ","
-h -1 -m17
The output takes up as many spaces as the size of the field I'm selecting inthe stored procedure...I'd prefer not to do a trimr in the stored procedure on all my character fields...Any thoughts?
USing SQLCMD on SQL version 2016 and I want to remove white spaces from my output. I've tried the -W -s switches and I still get white spaces
Here's my code
SQLCMD -S myserver -d mydb -b -Q "exec dbo.GetiBottaItemFile"
-o "myfile" -W -s ","
-h -1 -m17
The output takes up as many spaces as the size of the field I'm selecting in the stored procedure.I'd prefer not to do a rtrim in the stored procedure on all my character fields. Any thoughts?

Related

How to use shell variable in MQTT

I am new to shell scripting and MQTT.
I need to publish a JSON file using MQTT. We can do it by storing the JSON contents in a shell variable. But it is not working for me.
my shell script:
#!/bin/sh
var1='{"apiVersion":"2.1","data":{"id":"4TSJhIZmL0A","uploaded":"2008-07-15T18:11:59.000Z","updated":"2013-05-01T21:01:49.000Z","uploader":"burloandbardsey","category":"News","title":"bbc news start up theme","description":"bbc","thumbnail":{"sqDefault":"http://i.ytimg.com/vi/4TSJhIZmL0A/default.jpg","hqDefault":"http://i.ytimg.com/vi/4TSJhIZmL0A/hqdefault.jpg"},"player":{"default":"http://www.youtube.com/watch?v=4TSJhIZmL0A&feature=youtube_gdata_player","mobile":"http://m.youtube.com/details?v=4TSJhIZmL0A"},"content":{"5":"http://www.youtube.com/v/4TSJhIZmL0A?version=3&f=videos&app=youtube_gdata","1":"rtsp://v5.cache7.c.youtube.com/CiILENy73wIaGQlAL2aGhIk04RMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp","6":"rtsp://v5.cache7.c.youtube.com/CiILENy73wIaGQlAL2aGhIk04RMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"},"duration":15,"aspectRatio":"widescreen","rating":4.6683936,"likeCount":"354","ratingCount":386,"viewCount":341066,"favoriteCount":0,"commentCount":155,"accessControl":{"comment":"allowed","commentVote":"allowed","videoRespond":"allowed","rate":"allowed","embed":"allowed","list":"allowed","autoPlay":"allowed","syndicate":"allowed"}}}'
mosquitto_pub -h localhost -t test -m "$var1"
echo "$var1"
my Mosquitto commands:
Publisher: `mosquitto_pub -h localhost -t "test" -m "{"Contents":$var1}"
Subscriber: mosquitto_sub -h localhost -t "test"
Output I got:
{"Contents":}
Expected Output:
{"Contents":{"name":"Harini", "age":24, "city":"NewYork", "message":"Hello world"}}
I can get the output only at the terminal because of echo. But I want to publish and subscribe to the contents of the shell variable(var1)
Please help me out to get the output. Whether I need to add some more code in the shell script. I don't know how to proceed. Or can you suggest any other method.
The following works just fine, it's all about which quotes you use where:
#!/bin/sh
var1='{"name":"Harini", "age":24, "city":"NewYork","message":"Hello world"}'
echo $var1
mosquitto_pub -t test -m "{\"Content\": $var1}"
You need to wrap the -m argument in quotes because it contains spaces, which in turn means you need to escape the " round Content.
Wrapping the content of var1 in single quotes means you don't need to escape the double quotes in it.

Opening gnome-terminal and running script in tcl

When I try to execute below command it is showing Error like "extra characters after close-quote" but I gave it properly & when i try to it in unix command line terminal is opening properly.
exec gnome-terminal -e 'sh -c "bsub -Ip -n 1 -M <Memory> -q <queue_name> make"'
Can any one help me to resolve this issue or is there any way to do the same thing ??
Edited -> changed " from before sh to before bsub
Tcl's quoting is not the shell's quoting. Tcl uses {…} like the shell uses single quotes, except that braces nest nicely. Nesting single quotes is a recipe for shell headaches.
exec gnome-terminal -e {sh -c "bsub -Ip -n 1 -M <Memory> -q <queue_name> make"}
However, in this case I'd instead be tempted to go with this:
set memory "<Memory>"
set queue "<queue_name>"
set command "make"
set bsubcmd "bsub -Ip -n 1 -M $memory -q $queue $command"
# It's much more convenient to build this command like this here.
# Otherwise you're doing lots of backslashes and so on and it's horrible and very easy to make bugs
exec gnome-terminal -e [format {sh -c "%s"} $bsubcmd]
The only really messy thing is that command and bsubcmd have to be built using shell syntax if you're passing spaces around. “Fortunately” you're dealing with make anyway, so you probably really want to avoid having spaces in names passed there.

Passing "|" as an argument to unix script

I have written a generic unix script to load oracle table from any csv.Now the delimeter(field seperator) in the csv can be anything like ',' or '|" or ':' etc.
Hence i am trying to pass the delimeter as an argument to the script explicitly and its working fine for most of the delimeters but when i am trying to pass | then its not giving me proper result as it is implicitly converting | to ,
ksh -x myscript csv_name |
# not working
ksh -x myscript csv_name ,
# working
Please suggest me if there is in escape used for this?
Tested in my machine, you need to use below command -
ksh -x test.sh file "|"
OR
ksh -x test.sh file \|
OR
ksh -x test.sh file '|'
We need to disable the functionality of "|" using escape,single or double quotes.
Testing -
cat file
A|B|B|A
A|A|A
B|A|B|A
B|B
A|A
A|B
A|A|B
cat test.sh
vFile=$1
sep=$2
awk -F "$sep" '{print $1,$2}' ${vFile}
ksh -x test.sh file "|"
A B
A A
B A
B B
A A
A B
A A

sqlcmd output file remove header and footer

Using SQLCMD, I can output the query result to a text file, now, the text file has header:
And footer:
How do I remove them during query?
My query, inside a sql file:
SELECT internal_no, item_no, dspl_descr, rtl_prc FROM PLU
My SQLCMD command:
SQLCMD -S SQLSERVER01 -U AdminUser -P au5584 -i C:\text.sql -o C:\out.txt
Add
SET NOCOUNT ON
To the top of your query
SET NOCOUNT ON
SELECT internal_no, item_no, dspl_descr, rtl_prc FROM PLU
And add "-h-1" your SQLCMD command to:
SQLCMD -h-1 -S SQLSERVER01 -U AdminUser -P au5584 -i C:\text.sql -o C:\out.txt

Bash for loop picking up filenames and a column from read -r and gnu plot

The top part of the following script works great, the .dat files are created via the MySQL command, and work perfectly with gnu plot (via the command line). The problem is getting the bottom (gnuplot) to work correctly. I'm pretty sure I have a couple of problems in the code: variables and the array. I need to call each .dat file (plot), have the title in the graph (from title in customers.txt)and name it (.png)
any guidance would be appreciated. Thanks a lot -- RichR
#!/bin/bash
set -x
databases=""
titles=""
while read -r ipAddr dbName title; do
dbName=$(echo "$dbName" | sed -e 's/pacsdb//')
rm -f "$dbName.dat"
touch "$dbName.dat"
databases=("$dbName.dat")
titles="$titles $title"
while read -r period; do
mysql -uroot -pxxxx -h "$ipAddr" "pacsdb$dbName" -se \
"SELECT COUNT(*) FROM tables WHERE some.info BETWEEN $period;" >> "$dbName.dat"
done < periods.txt
done < customers.txt
for database in "${databases[#]}"; do
gnuplot << EOF
set a bunch of options
set output "/var/www/$dbName.png"
plot "$dbName.dat" using 2:xtic(1) title "$titles"
EOF
done
exit 0
customers.txt example line-
192.168.179.222 pacsdbgibsonia "Gibsonia Animal Hospital"
Error output.....
+ for database in '"${databases[#]}"'
+ gnuplot
line 0: warning: Skipping unreadable file ".dat"
line 0: No data in plot
+ exit 0
to initialise databases array:
databases=()
to append $dbName.dat to databases array:
databases+=("$dbName.dat")
to retrieve dbName, remove suffix pattern .dat
dbName=${database%.dat}