The UNIX and Linux Forums  

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
how to write shell script to take back up amitpansuria Shell Programming and Scripting 5 06-01-2008 10:42 AM
I need to write a shell script. lakshmanrk Shell Programming and Scripting 6 06-20-2007 07:00 AM
need help to write shell script getdpg Shell Programming and Scripting 0 04-10-2006 11:30 AM
Help needed to write a shell script! sreedharsn Shell Programming and Scripting 3 10-11-2005 01:21 PM
Beginner trying to write a shell script! duncan_glover Shell Programming and Scripting 3 08-19-2002 11:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-16-2006
rvrao77 rvrao77 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 6
please Write a shell script

Hi Team,

I am unable to write script. please guide me. My rquirement is as given below

one file will have three columns with n number of rows like
hostname port sid
-------- ---- ---
sun056 1527 PSP1
sun111 1529 PRP1
sun107 1580 PRD1

the script should read all rows in a column and each row should change to like below given format . all will goes to one file.

PSP1-SUN056.WORLD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST = sun056)(PORT = 1527))
)
(CONNECT_DATA =
(SID = PSP1)
)
)

Please write a shell script and send it to me.

Thanks
Venkat
  #2 (permalink)  
Old 11-16-2006
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
use

#! /usr/bin/ksh

while read line
do

hostname=`echo $line | cut -d" " -f1`
port=`echo $line | cut -d" " -f2`
sid=`echo $line | cut -d" " -f3`

echo "PSP1-SUN056.WORLD =\n (DESCRIPTION = \n (ADDRESS_LIST =" >>oraconn
echo "(ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST = $hostname)(PORT = $por
t))\n )\n (CONNECT_DATA =\n (SID= $sid\n)\n)" >>oraconn
done < $1
  #3 (permalink)  
Old 11-16-2006
cskumar cskumar is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 67
try this one

awk '{ printf("%s-%s.WORLD =\n(DESCRIPTION =\n(ADDRESS_LIST =\n(ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST = %s)(PORT = %s))\n)\n(CONNECT_DATA =\n(SID = %s)\n)\n)\n",$3,$1,$1,$2,$3)}' file
  #4 (permalink)  
Old 11-16-2006
rvrao77 rvrao77 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 6
Hi aju_kup,

thanks. Its working but one problem is there i.e file last line is not reading.
Suppose 32 lines there then its reading 31 lines only. Please tell me.

Thanks all for your support.

Thanks
Venkat
  #5 (permalink)  
Old 11-16-2006
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
I think there is blank line at end of input file. use the following

#! /usr/bin/ksh

while read line
do

if [[ ! -n $line ]]
then
exit
fi

hostname=`echo $line | cut -d" " -f1`
port=`echo $line | cut -d" " -f2`
sid=`echo $line | cut -d" " -f3`

echo "$sid-$hostname.WORLD =\n (DESCRIPTION = \n (ADDRESS_LIST =" >>oraconn
echo "(ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST = $hostname)(PORT = $por
t))\n )\n (CONNECT_DATA =\n (SID= $sid\n)\n)" >>oraconn
done < $1
  #6 (permalink)  
Old 11-16-2006
nilesrex nilesrex is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 43
try this....

eecho "hostname port sid^J-------- ---- ---^Jsun056 1527 PSP1^Jsun111 1529 PRP1^Jsun107 1580 PRD1^J" | sed 1,2d | \
awk '{ print $3 "-" $1 ".WORLD =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST =" $1 ")(PORT = " $2")))(CONNECT_DATA =(SID = " $3 ")))" }'
  #7 (permalink)  
Old 11-16-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
The cskumar solution with simple data validation (check port number) :

Code:
awk '
     BEGIN {
        fmt =      "%s-%s.WORLD=\n(DESCRIPTION =\n(ADDRESS_LIST =\n"
        fmt = fmt "(ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST = %s)(PORT = %s))\n"
        fmt = fmt ")\n(CONNECT_DATA =\n(SID = %s)\n)\n)\n";
     }
     $2 ~/^[0-9]{1,}$/ { 
        printf(fmt, toupper($3) ,toupper($1) ,$1, $2, $3)
     }' file

Jean-Pierre.
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 07:29 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