The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 06-01-2007
praveenkumar_l's Avatar
praveenkumar_l praveenkumar_l is offline
Registered User
 

Join Date: May 2007
Posts: 36
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')"
Reply With Quote