I am trying to write a shell script that inserts data in postgres:
First Part:
#!/usr/bin/env bash
for f in /folder/*.sql; do
psql -U postgres -f $f
done
for f in /folder1/*.sql; do
psql -U postgres -f $f
done
I need to add several conditions on it.
- I need to sort file names for folder. Example my folder has files a.sql, c.sql, b.sql
I want to sort them on basis of name so first a.sql should be inserted then b.sql and then c.sql.
- For folder1 there exists some unwanted files, i want to ignore them(which is happening now also) and first i want to insert the files having base fields and then other tables.
Example folder1 has 1.sql, a.txt, 3.sql, base.sql.
I do not want to insert a.txt And first base.sql should be inserted and then 1.sql and 3.sql
How to do it via shell script?