![]() |
|
|
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 |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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 ")))" }' |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|