Importing data with bcp - cmd

I would like to import data in the file 'c:_value_.txt' to my database like this
Bcp mydb.mytable in 'C:\_value_.txt' -T -c -Smypc\instancename
However I keep getting the error
Unable to open BCP host data -file
Why is this?

Lose the single quotes around the filename. Either use no quotes, or use double quotes ("") if the name contains spaces and such.

Removing the single quotes was able to solve this

Related

how to remove single quotes from a string using truncate in bash

In my shell script, condition for a show command is like this:
if (arr["bid_present"] == "'true'")
In this, I want to remove the single quotes from the boolean data and as the output of the show command should be without single quotes.
Can anyone please help on how to remove these single quotes using tr -d, from the output of the above bash script.
Thanks in advance.

sed with regular expression as a bash variable

We have an application that keeps some info in an encrypted file. To edit the file we have to put the text editor name in an environment variable in bash, for example, EDITOR=vi. Then we run the application and it opens the decrypted file in vi. I am trying to come up with a bash script that updates the encrypted file. The only solution that I can think of is passing sed command instead of vi to the EDITOR variable. It works perfectly for something like EDITOR='sed -i s#aaaa#bbbb#'.
Problem starts when I need space and regular expression. For example: EDITOR='sed -i -r "s#^(\s*masterkey: )(.*)#\1xxxxx#"' which return error. I tried running the EDITOR in bash with $EDITOR test.txt and I can see the problem. It doesn't like double quotes and space between them so I added a backslash before the double quotes and \s instead of space. Now it says unterminated address regex. For several hours I googled and couldn't find any solution. I tried replacing single quotes with double quotes and vice versa and everything that I could find on the internet but no luck.
How can I escape and which characters should I escape here?
Update:
Maybe if I explain the whole situation somebody could suggest an alternative solution. There is an application written by Ruby and it is inside a container. Ruby application has a secret_key_base for production and we supposed to change the key with EDITOR=vi rails credentials:edit --environment=production. I don't know Ruby and google did not return any ruby solution for automation so I could only think about sending sed instead of vi to Ruby.
How can I escape and which characters should I escape here?
That is not possible. Word splitting on the result of expansion cannot be escaped from inside the result of that expansion, it will always run. Note that filename expansion is also running over the result of the expansion.
Create an executable file with the script content and set EDITOR to it.
You could export a bash shell function, after some tries I got to:
myeditor() {
sed -i -E 's#^(\s*masterkey: )(.*)#\1xxxxx#' "$#"
}
export -f myeditor
EDITOR='bash -c "$#" _ myeditor'

Quotes in sh -c command - syntax error [duplicate]

This question already has answers here:
How to escape single quotes within single quoted strings
(25 answers)
Closed 4 years ago.
I want to execute the following command by using sh -c (because I want to append similar commands later):
impala-shell -q "CREATE TABLE test LIKE PARQUET 'hdfs://.../foo.parquet' STORED AS PARQUET"
This command works fine. But if I try
sh -c 'impala-shell -q "CREATE TABLE test LIKE PARQUET 'hdfs://../foo.parquet' STORED AS PARQUET"'
I get a syntax error:
LIKE PARQUET hdfs://.../...
^
There must be something wrong with the single quotes from the hdfs path but I can't figure it out. The hdfs path needs to be in quotes. I also tried to backslash them with /' which should actually work according to the docs. I hope someone can help me with that.
You can use Python to tell you how to quote a shell command. Yes, really. :)
python -c '
import sys
try:
from pipes import quote
except ImportError:
from shlex import quote
print(quote(sys.stdin.read().rstrip("\n")))
' <<'EOF'
impala-shell -q "CREATE TABLE test LIKE PARQUET 'hdfs://.../foo.parquet' STORED AS PARQUET"
EOF
...emits as output:
'impala-shell -q "CREATE TABLE test LIKE PARQUET '"'"'hdfs://.../foo.parquet'"'"' STORED AS PARQUET"'
...and indeed, you can succesfully run:
sh -c 'impala-shell -q "CREATE TABLE test LIKE PARQUET '"'"'hdfs://.../foo.parquet'"'"' STORED AS PARQUET"'
Because everything in single-quotes is literal, including backslashes, you need to change to a different quoting context in order to include a single quote literal in a single-quoted string.
That's what '"'"' does: First, it ends the single-quoted context; then it enters a double-quoted context; then it inserts a literal '; then it ends the double-quoted context; then it goes back into a single-quoted context.

Is it possible to wrap a Doxygen filter command in quotes?

I am trying to write a Doxygen file filter that lives in a subdirectory that works from Doxyfile on both Windows and Linux.
Doxyfile
/scripts
myfilter
I seem to be unable to specify the path using a forward-slash on Windows unless it is quoted:
"scripts/myfilter"
However, trying to quote the command in Doxyfile does not work.
FILTER_PATTERNS = *.glsl=""scripts/runpython" scripts/doxygen-glslfilter.py"
On Windows, you get an error that implies the quotes don't exist.
'scripts' is not recognized as an internal or external command, operable program or batch file.
Doxygen uses popen() to run these commands and will remove the wrapping quotes around the command, but it does not seem to remove all quotes.
popen() call:
https://github.com/doxygen/doxygen/blob/master/src/definition.cpp#L745
filter name quote strip:
https://github.com/doxygen/doxygen/blob/master/src/util.cpp#L2458
However, the result is the same as if there were no quotes.
Update
I was able to get command logging in Doxygen, and it appears the extra quotes are being stripped in an odd way. You can see how there is a space in front of the command.
Executing popen(` scripts/runpython scripts/doxygen-glslfilter.py "C:/dev/g3d/G3D10/data-files/shader/AlphaFilter.glsl"`)
Update
I submitted a bug report/feature request but I doubt it will be read.
Doxygen Bug Report
The issue was reported to the doxygen project, and they have provided a solution where any '/' in the command is replaced by '\' on Windows.
https://bugzilla.gnome.org/show_bug.cgi?id=792846
This was done to resolve a similar issue here:
What is the QHG_LOCATION path relative to for doxygen?
The pull request for the project on github here: https://github.com/doxygen/doxygen/pull/703
When using double quotes within double quotes in a single string, it sees the first double quote as the start string and the next double quote as the end of the string.
So in your example:
""scripts/runpython" scripts/doxygen-glslfilter.py"
The first 2 quotes are seen as open and close, then it sees scripts/runpython as the next command etc.
I do not have the same tool, but these 2 examples will probably sort out your issue.
This example wraps each set in double quotes, and the entire set in single quotes.
FILTER_PATTERNS = *.glsl='"scripts/runpython" "scripts/doxygen-glslfilter.py"'
Where this example wraps the first set in double quotes and the entire set in single quotes.
FILTER_PATTERNS = *.glsl='"scripts/runpython" scripts/doxygen-glslfilter.py'
NOTE!! I am unable to test this as I do not have the same environment as you. I am therefore not sure if the second option will work, as it might also need scripts/doxygen-glslfilter.py in double quotes, I am adding it to the answer regardless.

wget errors breaks shell script - how to prevent that?

I have a huge file with lots of links to files of various types to download. Each line is one download command like:
wget 'URL1'
wget 'URL2'
...
and there are thousands of those.
Unfortunately some URLs look really ugly, like for example:
http://www.cepa.org.gh/archives/research-working-papers/WTO4%20(1)-charles.doc
It opens OK in a browser, but confuses wget.
I'm getting an error:
./tasks001.sh: line 35: syntax error near unexpected token `1'
./tasks001.sh: line 35: `wget 'http://www.cepa.org.gh/archives/research-working-papers/WTO4%20(1)-charles.doc''
I've tried both URL and 'URL' ways of specifying what to download.
Is there a way to make a script like that running unattended?
I'm OK if it'll just skip the file it couldn't download.
Do not (ab)use the shell.
Save your URLs to some file (let's say my_urls.lst) and do:
wget -i my_urls.lst
Wget will handle quoting etc on it's own
I think you need to used double-quotes (") and not single quotes (') around the URL.
If that still doesn't work, try escaping the paren characters ( and ) with a backslash: \( and \)
Which shell are you using? Bash? zsh?
This doesn't exactly answer your question but:
Both of the following commands work directly in a bash shell:
wget "http://www.cepa.org.gh/archives/research-working-papers/WTO4%20(1)-charles.doc"
and
wget 'http://www.cepa.org.gh/archives/research-working-papers/WTO4%20(1)-charles.doc'
Can you check to see if either of those work for you?
What seems to be happening is that your shell is doing something with the ( characters. I would try using double quotes " instead of single quotes ' around your URL.
If you wish to suppress errors you can use a >/dev/null under unix to redirect standard output or 2> /dev/null to redirect standard error. Under other operating systems it may be something else.

Resources