The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-31-2007
bsrajirs bsrajirs is offline
Registered User
  
 

Join Date: May 2007
Posts: 11
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.
  #2 (permalink)  
Old 06-01-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
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
Jean-Pierre.
  #3 (permalink)  
Old 06-01-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
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 (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')"
  #5 (permalink)  
Old 06-01-2007
bsrajirs bsrajirs is offline
Registered User
  
 

Join Date: May 2007
Posts: 11
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0