Reputation:
I've got a shell script which merges all my migration and seeder files to two bigger files, but I want to merge migrate.sql and seed.sql into just one big file called deploy.sql.
Is there a way with AWK to accept multiple directories into one final file?
Example:
#!/bin/bash
mkdir -p output
awk '{print}' ./migrations/*.sql > "output/migrate.sql"
awk '{print}' ./seeders/*.sql > "output/seed.sql"
Upvotes: 0
Views: 13
Reputation: 36755
Is there a way with AWK to accept multiple directories into one final file?
GNU AWK
does not accept directories, but rather files, in your case
awk '{print}' ./migrations/*.sql > "output/migrate.sql"
awk '{print}' ./seeders/*.sql > "output/seed.sql"
argument with *
is replaced by all files compliant with descripition before being rammed into awk
, consider following example, say you have only following files in current dir
file1.txt
file2.txt
file3.txt
which are empty then
awk 'BEGIN{print ARGV[1],ARGV[2],ARGV[3]}' file*.txt
does output
file1.txt file2.txt file3.txt
Observe that even in BEGIN, ARGV
has entry for each file, rather than single entry with file*.txt
.
You might use more than 1 argument with *
when using GNU AWK
that is you might do
awk '{print}' ./migrations/*.sql ./seeders/*.sql > "output/deploy.sql"
(tested in gawk 4.2.1)
Upvotes: 1