- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Read words from file and create new file using...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2007 12:24 PM
тАО05-31-2007 12:24 PM
Read words from file and create new file using K-shell.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2007 01:12 PM
тАО05-31-2007 01:12 PM
Re: Read words from file and create new file using K-shell.
Then take all of the names on the right and do the same thing. Then put out those two lines?
I assume you don't care about the order of the lists of the first two lines and that you may output:
SCHEMAS=OWNER1,OWNER
INCLUDE=TABLE:"IN ('TABLE_NAME','TABLE_NAME1')"
And that the total number of lines in the input files is S * I?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2007 02:24 PM
тАО05-31-2007 02:24 PM
Re: Read words from file and create new file using K-shell.
Yeah, why not a perl or awk solution?
This is not a shell or scripting task, it is word processing task.
In perl it could look like
$cat x.txt
OWNER.TABLE_NAME
OWNER.TABLE_NAME1
OWNER1.TABLE_NAME
OWNER1.TABLE_NAME1
$cat x.pl
use strict;
my (%owners, %tables);
while (<>) {
chomp;
my ($o,$t) = split /\./;
$owners{$o}++;
$tables{$t}++;
}
my $owner_list = join q(,), sort keys %owners;
my $table_list = join q(','), sort keys %tables;
print <<"EOF";
SCHEMAS=$owner_list
INCLUDE=TABLE:"IN ('$table_list')"
EOF
$perl x.pl x.txt
SCHEMAS=OWNER,OWNER1
INCLUDE=TABLE:"IN ('TABLE_NAME','TABLE_NAME1')"
Cheers!
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2007 02:58 PM
тАО05-31-2007 02:58 PM
Re: Read words from file and create new file using K-shell.
TMP=/var/tmp/itrc.sc.$$
awk -F. -v OUT2=${TMP}b '
{
print $1
print $2 >> OUT2
} ' input-file | sort -u > ${TMP}a
sort -u -o ${TMP}b ${TMP}b
IFS_SAVE=$IFS
set -A SCH -- $(< ${TMP}a )
IFS=","
echo "SCHEMAS=${SCH[*]}"
IFS=$IFS_SAVE
set -A SCH -- $(< ${TMP}b )
echo "INCLUDE=TABLE:\"IN ('\c"
(( i = 0 ))
(( j = ${#SCH[*]} ))
while [ $i -lt $j ]; do
echo "${SCH[i]}\c"
(( i = i + 1 ))
if [ $i -lt $j ]; then
echo "','\c"
fi
done
echo "')"\"
rm -f ${TMP}a ${TMP}b
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2007 05:28 PM
тАО05-31-2007 05:28 PM
Re: Read words from file and create new file using K-shell.
Thanks a lot for your response...
Yes, you are correct.. Order is not a problem.
I will try with the awk script and let you if there are any issues.
In the script, i am not using the perl...
Thanks!
bsraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2007 06:42 PM
тАО05-31-2007 06:42 PM
Re: Read words from file and create new file using K-shell.
T1=`cat xxx|cut -d\. -f1|sort -u`
echo $T1| tr " " "," | \
sed 's|^|SCHEMAS=|g'
T1=`cat xxx|cut -d\. -f2|sort -u`
echo $T1| tr " " ","|sed \
-e"s|^|\'|g" \
-e"s|$|\'|g" \
-e"s|^|INCLUDE=TABLE:\"IN \(|g" \
-e"s|$|\)\"|g"
- Tags:
- cut
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-01-2007 05:41 AM
тАО06-01-2007 05:41 AM
Re: Read words from file and create new file using K-shell.
is it acceptable to generate a file that *says* all owners have all tables?
for example
O.T
0.T1
01.T
01.T1
02.T3
should this say
SCHEMAS=0,01,02
INCLUDE=TABLE:"IN('T','T1','T2')"
or
SCHEMAS=0,01
INCLUDE=TABLE:"IN('T','T1')"
SCHEMAS=02
INCLUDE=TABLE:"IN('T3')"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-02-2007 06:45 AM
тАО06-02-2007 06:45 AM
Re: Read words from file and create new file using K-shell.
Thanks for your response..
I am not sure how to modify ur code to get single codes after all the tables..
Could you please hele me to get that..
The Output from the same code.
SCHEMAS=OWNER,OWNER1
INCLUDE=TABLE:"IN ('TABLE_NAME,TABLE_NAME1')"
I like to get single codes after every table.
SCHEMAS=OWNER,OWNER1
INCLUDE=TABLE:"IN ('TABLE_NAME','TABLE_NAME1')"
Please let me know there are any quesitons.
Thanks,
bsraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-02-2007 06:51 AM
тАО06-02-2007 06:51 AM
Re: Read words from file and create new file using K-shell.
Again thanks..
Yes, i need to make the output file as your first like guess.
should this say
SCHEMAS=0,01,02
INCLUDE=TABLE:"IN('T','T1','T2','T3')"
I have added the table T3 in the output..
Please let me know there are any quesitons.
Thanks,
bsraj.