-
Notifications
You must be signed in to change notification settings - Fork 5
/
.bash_tips
33 lines (25 loc) · 997 Bytes
/
.bash_tips
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# vim: set ft=sh:
# Recursive find and replace in files
find ./ -type f -exec sed -i -e 's/apple/orange/g' {} \;
### POSTGRES
# postgres: copy database
createdb -O ownername -T originaldb newdb
# Run a query and put the results on a file
psql -d dbname -t -A -F"," -c "select * from users" > output.csv
## KILL a PID
# check running processes
select * from pg_stat_activity where state = 'active';
# Find the process you want to kill, then type:
select pg_cancel_backend(<pid of the process>)
# If the process cannot be killed, try:
select pg_terminate_backend(<pid of the process>)
### SED
# delete matching lines from file inplace
sed -i '/declines,/d' backfiller_surveys.csv
# remove a string from each matching line in a file inplace
sed -i 's/apple//' backfiller_surveys.csv
# substitue a string with another from a file inplace
sed -i 's/apple/orange/' backfiller_surveys.csv
#### TAIL
# delete the first line of a big file
tail -n +2 "$FILE" > "$FILE.tmp" && mv "$FILE.tmp" "$FILE"