![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 10:19 AM |
| Need to create file from shell scripting | smr_rashmy | Shell Programming and Scripting | 4 | 01-28-2008 07:59 PM |
| how to read all the unique words in a text file | aditya.ece1985 | Shell Programming and Scripting | 5 | 11-29-2007 11:26 PM |
| FTP is using shell scripts create ? for file | a501420038 | Shell Programming and Scripting | 1 | 08-16-2007 11:39 AM |
| Post Shell programming: Question about source a file and read data from the file | ccwq | Shell Programming and Scripting | 3 | 08-04-2007 07:28 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
A possible solution using awk :
Code:
awk -F'.' -v Q="'" '
{
schemas[$1]++;
include[$2]++;
}
END {
for (s in schemas)
schemas_list = schemas_list (schemas_list ? "," : "") s;
for (i in include)
include_list = include_list (include_list ? "," : "") Q i Q;
print "SCHEMAS=" schemas_list;
print "INCLUDE=TABLE:\"IN (" include_list ")\"";
}
' infile
|
|
#3
|
|||
|
|||
|
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
|
|
#4
|
||||
|
||||
|
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')" |
|
#5
|
|||
|
|||
|
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.. |
|||
| Google The UNIX and Linux Forums |