Skip to main content
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 ...
Kusalananda's user avatar
  • 356k
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 ...
Kusalananda's user avatar
  • 356k
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 (...
RomanPerekhrest's user avatar
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 ...
anishpatel's user avatar
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,...
pLumo's user avatar
  • 23.2k
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,...
Jakuje's user avatar
  • 21.8k
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 ...
Vladimir Botka's user avatar
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 ...
Kusalananda's user avatar
  • 356k
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 ...
Steve Daulton's user avatar
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" ...
Kusalananda's user avatar
  • 356k
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"...
igal's user avatar
  • 10.2k
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}": .[...
RomanPerekhrest's user avatar
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 , ...
JJoao's user avatar
  • 12.8k
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.
ajgringo619's user avatar
  • 3,634
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 ...
muru's user avatar
  • 77.9k
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:]]+)\) ...
DanieleGrassini's user avatar
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=( $(...
Saboteur's user avatar
  • 186
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 "%...
schrodingerscatcuriosity's user avatar
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 ...
B Layer's user avatar
  • 5,261
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 ...
Kusalananda's user avatar
  • 356k
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 ...
Jeff Schaller's user avatar
  • 68.8k
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 ...
Sir Jo Black's user avatar
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 ...
AlexP's user avatar
  • 10.8k
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 ...
dr_'s user avatar
  • 32.4k
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 ....
Romeo Ninov's user avatar
  • 19.5k
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 ...
Kusalananda's user avatar
  • 356k
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 ...
terdon's user avatar
  • 252k
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 ...
aborruso's user avatar
  • 3,005
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 ...
jasonwryan's user avatar
  • 74.8k

Only top scored, non community-wiki answers of a minimum length are eligible