'Creating Multiple Workfile using Bash Script
I m trying to create a multiple workfiles
Source csv file
**Filename,SchemaName,TableName
Shelf,category,books
Door,Category,wood**
Expected Output
each Filename from column 1
Shelfy.wrk
\`File content Shelf.wrk
Your table is category.books\`
Door.wrk
\`File content Door.wrk
Your table is category.wood\`
I tried to create something like
sed 's/,/\\n/g' file | while read fileName; do touch "$fileName".wrk; done
but not sure how to populate the content by form row by row to seperate file
Solution 1:[1]
As user1934428 mentioned, there's no need to use sed at all, but awk.
awk '(NR!=1)' source.csv | awk -F, '{fName=$1".wrk";cat=$2;tbl=$3; print fName"\nFile content "fName"\nYour table is "cat"."tbl}'
First let's skip the first line with awk '(NR!=1)' source.csv
Then instruct awk to use comma as field separator with -F, (as IFS=, would do)
Assign each column value to a variable. For file name extension .wrk is appended: fName=$1".wrk". For the other two columns: cat=$2;tbl=$3;
Finally you only print the strings
print fName"\nFile content "fName"\nYour table is "cat"."tbl
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alfredo Campos EnrĂquez |
