Quote:
|
Originally Posted by bsrajirs
Hi All,
Please help me in creating files through K-shell scripts.
I am having one file in this format.
OWNER.TABLE_NAME
OWNER.TABLE_NAME1
OWNER1.TABLE_NAME
OWNER1.TABLE_NAME1
I want to read the above file and create new file through k shell script.
The new file should looks like this.
SCHEMAS=OWNER,OWNER1
INCLUDE=TABLE:"IN ('TABLE_NAME','TABLE_NAME1')"
Please let me know there are any questions.
Thanks,
bsraj.
|
Try this. This may not be a generic version.
$ cat file1.ksh
#!/usr/bin/ksh
schemas=$(cut -f1 -d. file1 | sort -u | xargs |
sed 's/ /,/')
tables=$(cut -f2 -d. file1 | sort -u | xargs |
sed -e 's/ /,/' -e "s/.*/'&/" -e "s/,/','/" -e "s/.*/&'/")
echo "SCHEMAS=$schemas\nINCLUDE=TABLE:\"IN ($tables)\""
$ file1.ksh
SCHEMAS=OWNER,OWNER1
INCLUDE=TABLE:"IN ('TABLE_NAME','TABLE_NAME1')"