22
votes
How does this shebang that starts with a double hyphen (--) work?
Related: Which shell interpreter runs a script with no shebang?
The script does not have a shebang/hashbang/#! line, simply because a double dash is not #!.
However, the script will be executed by a ...
8
votes
SQL operation on csv file using bash or shell
Using csvkit,
$ csvsql -H --query 'SELECT a,min(b),max(c),d FROM file GROUP BY a' file.csv
a,min(b),max(c),d
164318,1449,1457,1922
841422,1221,1228,1860
842179,2115,2118,1485
846354,1512,1513,1590
...
7
votes
Accepted
converting insert into to select
Complex AWK solution:
awk -F'[()]' '{ sub(/INSERT INTO */,"",$1);
printf "SELECT * FROM %s WHERE ",$1;
len=split($2, f, ","); split($4, v, ",");
for (...
7
votes
vim: Force specific syntax via command-line argument
vim -R -c 'set ft=sql' -
-R opens Vim in read-only mode. Your system may have the alias view for vim -R, but Neovim does not support it.
set ft is short for set filetype. As Martin Tournoij mentioned ...
6
votes
SQL operation on csv file using bash or shell
Using csvkit:
csvsql -H --query "select a,min(b),max(c),d from file group by a,d" file.csv
Note, that this will truncate the leading 0.
Output:
a,min(b),max(c),d
164318,1449,1457,1922
841422,1221,...
5
votes
Accepted
Get rid of \n in Ansible Jinja template
The jinja templates have whitespace control:
https://ttl255.com/jinja2-tutorial-part-3-whitespace-control/
generally, using the - sign should get rid of the whitespaces:
INSERT INTO mytable(hostname,...
5
votes
Get rid of \n in Ansible Jinja template
For example,
- hosts: localhost
vars:
h: localhost
hostname: server1138
foo: blah
sql: >-
INSERT INTO mytable(hostname,foo,...)
{% if hostvars[h]['something'] is ...
4
votes
Running a Python that calls a SQL in BASH W10
The Python script runs in an environment where the sqlcmd is not found in any of the directories that are listed in the PATH environment variable.
Make sure that PATH includes the directory where ...
4
votes
Accepted
ansi: two fast questions about this term
ANSI is the "American National Standards Institute". They are and organisation that defines standards for a very wide range of things: "from acoustical devices to construction equipment, from dairy ...
4
votes
Accepted
What does `join` do in terms of equijoin in SQL or operations in relational algebra?
The join utility, by default, does what's called an "inner join" in SQL, resulting in the combined records of those entries whose join field is identical in both files. Yes, this is an "equi-join" ...
4
votes
converting insert into to select
Here's an alternative in Python, in case you're into that sort of thing (more verbose but more legible than awk, at least for me):
#!/usr/bin/env python2
# -*- coding: ascii -*-
"""transform_query.py"...
4
votes
Make JSON from SQL query output
jq solution:
<your sql output> | jq -Rs '{"data": [split("\n") | map(select(length > 0))[]
| split(" +";"g")
| {"{#HOSTNAME}": .[...
4
votes
Accepted
Split long SQL expression at delimiter
Try something like:
sed -re '/.{2500}/ s/.{,2500},/&\n/g'
Explanation:
/.{2500}/ if line contains 2500 characteres (or more) ...
s/.{,2500},/&\n/g substitute up to 2500 char followed by a , ...
3
votes
Accepted
Failed to find package in third party repository
Whenever you add a new repository, you need to update your apt cache so it will see the updated/new packages:
sudo apt update
Then you can run your install command as normal.
3
votes
Split long SQL expression at delimiter
I'd imagine something like this awk command would work:
awk 'length > 2499 {gsub(/.{0,2498},/, "&\n")} 1'
The regex allows for up to 2498 characters before a comma, (so 2499 ...
3
votes
Regular expression - SQL manipulation
Since you use fedora you have GNU sed and this should work:
s=" shipname NVARCHAR(40) NOT NULL,"
echo "$s" | sed -E '/NOT/{s/^ ([[:lower:]]+)\s*NVARCHAR\(([[:digit:]]+)\) ...
3
votes
Accepted
How to store query multiple result in shell script variable(Array)?
You need to change default separator IFS to split data by end of line character and disable globbing with set -f to avoid issues with strings containing e.g. * or ?:
$ IFS=$'\n'
$ set -f
$ result=( $(...
3
votes
How to store query multiple result in shell script variable(Array)?
In Bash you can use mapfile (it should be tested with your actual result):
# note that the parenthesis are not needed
$ result="HOUSE CAR
DOC CAT"
$ mapfile -t arr < <(printf "%...
2
votes
Delete multi-line strings
Using ex (aka vim in Ex mode):
ex +'%s/,\n *PRIM\_.*\ze\n) ENGINE//' +wq file
Just a "batch" version of the Vim substitute-delete (empty substitution //) which does multi-line match with \_.* and ...
2
votes
SQLite3 Query storing IP address syntax error
The issue is the quoting of the strings in the text fields.
Use a here-document (which enables you to write a nicer looking statement):
sqlite3 database <<END_SQL
UPDATE stats
SET ...
2
votes
REGEX search & replace with sed or other command
sed -e 's/\[code language="\([^"]*\)"\]/<pre><code class="language-\1">/' \
-e 's!\[/code\]!</code></pre>!' \
< input > output
The square brackets have to be ...
2
votes
How to compile a ".pc" file on Debian 9?
You may look for the pre-compiler starting from here:
https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/proc/proc.htm
Note that the pre-compiler needs the connection ...
2
votes
Accepted
Use sed to prefix and suffix multiple strings per line
Try:
sed -r -e 's/'\''[A-Z][a-z][a-z]\s+[0-9]+\s[0-9]{4}\s+[0-9]+:[0-9][0-9][AP]M'\''/STR_TO_DATE(&, '\''%b %d %Y %h:%i%p'\'')/g'
Notes:
'\'' is how you insert a single-quote in a single-quoted ...
2
votes
Forgot sql password for a certain user (debian)
Assuming you are talking about a MySQL server, and the bob user is a local user ('bob'@'localhost'), here's how to change the password of a MySQL user when you do not know the old password.
Login to ...
2
votes
Accepted
sqlplus doesn't work in Crontab
To run successfully in cron such job you need to set some variables like ORACLE_SID, ORACLE_HOME and so on. The samples way to do this is to make your script on this way:
source ~/.bashrc #or ....
2
votes
For 'a%' why is one of the results that could be returned 'z6ra'?
You have misread the patterns in the text you quote. You read a% where it says %a.
The pattern %a matches any string that ends with a. The string Z6ra ends with a, so the pattern would match it.
The ...
2
votes
Accepted
How to correctly handle apostrophes in Ansible templates for SQL statements?
You can try enclosing your values in double quotes instead of single ones. Of course, this still means they will break if the value can contain double quotes, but it should at least get you through ...
1
vote
SQL operation on csv file using bash or shell
With Miller (http://johnkerl.org/miller/doc), using
mlr --ocsv --quote-all --inidx --ifs , cat inputFile | \
mlr --ocsv --quote-none --icsvlite stats1 -g '"1"' -a min,max,min -f '"2","3","4"' \
then ...
1
vote
Installing Oracle SQL Developer in Arch
If you have installed it correctly, ie., so the software is tracked by pacman, then you can print a list of the binaries available with:
pacman -Ql $package | awk '/\/usr\/bin/'
In some case, the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sql × 154shell-script × 42
text-processing × 27
bash × 24
linux × 21
awk × 16
shell × 15
mysql × 14
sed × 13
ksh × 10
database × 10
scripting × 9
oracle × 9
oracle-database × 8
mariadb × 7
grep × 6
csv × 6
variable × 5
php × 5
quoting × 4
text-formatting × 4
postgresql × 4
sqlite × 4
debian × 3
regular-expression × 3