Skip to content

Commit 94d5a4a

Browse files
committed
feat(csv): ♻️ Add another sqlite example
1 parent d6723a4 commit 94d5a4a

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
22
.env
3+
out

12_csv/README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ Convert a TSV to CSV
3939
tr '\t' ',' < ./file.tsv > ./file.csv
4040
```
4141

42-
## Generate CSV from CPU data
43-
44-
```sh
45-
echo "time,cpu,pid,process" > ./cpu.csv
46-
for index in $(seq 0 100 );
47-
do
48-
ps -opcpu -opid -ocomm -cax | grep -i windowserver | sort -r | sed "s/^/$(date '+%H:%M:%S') /" | sed 's/\t/ /g' | sed 's/ */ /g' | sed 's/ /,/g'
49-
sleep 1
50-
done >> ./cpu.csv
51-
52-
sqlite3 :memory: -cmd '.mode csv' -cmd '.import cpu.csv cpu' 'SELECT time, COUNT(*), AVG(cpu) FROM cpu '
53-
```
54-
5542
## Remove Columns
5643

5744
```sh
@@ -61,5 +48,4 @@ cut -d',' -f4- ./out/mydata.csv > ./out/mydata_3_less_columns.csv
6148
## Resources
6249

6350
- My jq examples [here](../jq/README.md)
64-
- https://til.simonwillison.net/sqlite/one-line-csv-operations
6551
- TidyViewer [here](https://github.com/alexhallam/tv)

12_csv/SQLITE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SQLITE CSV QUERYING
2+
3+
## Logs
4+
5+
```sh
6+
sqlite3 :memory:
7+
8+
.help .mode
9+
10+
export CSV_FILE=''
11+
# import and print out schema (list is | seperator)
12+
sqlite3 :memory: -cmd '.mode list' -cmd ".import ${CSV_FILE} logs -v" 'SELECT * FROM logs LIMIT 10'
13+
# group by
14+
sqlite3 :memory: -cmd '.mode list' -cmd ".import ${CSV_FILE} logs -v" 'SELECT ip, COUNT(ip) FROM logs GROUP BY ip'
15+
```
16+
17+
## Generate CSV from CPU data
18+
19+
```sh
20+
echo "time,cpu,pid,process" > ./cpu.csv
21+
for index in $(seq 0 100 );
22+
do
23+
ps -opcpu -opid -ocomm -cax | grep -i windowserver | sort -r | sed "s/^/$(date '+%H:%M:%S') /" | sed 's/\t/ /g' | sed 's/ */ /g' | sed 's/ /,/g'
24+
sleep 1
25+
done >> ./cpu.csv
26+
27+
sqlite3 :memory: -cmd '.mode csv' -cmd '.import cpu.csv cpu' 'SELECT time, COUNT(*), AVG(cpu) FROM cpu '
28+
```
29+
30+
## Resources
31+
32+
- https://til.simonwillison.net/sqlite/one-line-csv-operations

0 commit comments

Comments
 (0)