![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script to Read Error,jbase,voilation,segmentation words from a file | Mujtaba khan | Shell Programming and Scripting | 3 | 03-30-2008 01:19 PM |
| Need to create file from shell scripting | smr_rashmy | Shell Programming and Scripting | 4 | 01-28-2008 10:59 PM |
| how to read all the unique words in a text file | aditya.ece1985 | Shell Programming and Scripting | 5 | 11-30-2007 02:26 AM |
| FTP is using shell scripts create ? for file | a501420038 | Shell Programming and Scripting | 1 | 08-16-2007 02:39 PM |
| Post Shell programming: Question about source a file and read data from the file | ccwq | Shell Programming and Scripting | 3 | 08-04-2007 10:28 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Read words from file and create new file using K-shell.
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. |
|
||||
|
Hope this is what you wanted
Code:
#!/bin/ksh
Input_File=$1
Temp_File=temp.txt
Output_File=output.txt
rm -f $Output_File 2> /dev/null
for list_of_users in `cut -d'.' -f1 $Input_File | sort | uniq`
do
for table_name in `grep -x "^$list_of_users\..*" $Input_File |cut -d'.' -f2`
do
tables=$tables","$table_name
done
echo $list_of_users":"${tables#,} >> $Temp_File
tables=""
done
for list_of_objects in `cut -d':' -f2 $Temp_File | sort | uniq`
do
for user_name in `grep -x "..*$list_of_objects\$" $Temp_File |cut -d':' -f1`
do
cmbuser=$cmbuser","$user_name
done
echo ${cmbuser#,}":"$list_of_objects >> $Output_File
cmbuser=""
done
mv $Output_File $Temp_File
for line in `cat $Temp_File`
do
echo $line | cut -d':' -f1 | read user_list
echo $line | cut -d':' -f2 | read table_list
echo "SCHEMAS=$user_list" >> $Output_File
echo 'INCLUDE=TABLE:"IN('$table_list')"' >> $Output_File
done
rm -f $Temp_File 2> /dev/null
exit
|
|
|||||
|
Quote:
$ 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')" |
|
||||
|
Thanks a lot..
Hi All,
Thank You All!! I am sure this will help me lot. I am working to test the codes.. I will let you know if there are any issues.. I Appreciate all your help.. Again Thanks to all... Regards, bsraj.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|