Replacing Port number Using Sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing Port number Using Sed
# 1  
Old 01-22-2010
Bug Replacing Port number Using Sed

Hi
Im trying to replace http port value.However for some reason its not working.Can you guys take a look and hit me with suggestions please.Your help is much appreciated.

Code:
echo "Enter Value"
read ans
sed -i "s/http-port = 80 /http-port = $ans/g" demo

Note:demo is the filename


Thanks guys
CK

Last edited by Scott; 01-22-2010 at 05:53 PM.. Reason: Please use code tags
# 2  
Old 01-22-2010
you getting any error??
# 3  
Old 01-22-2010
Im not getting errors however its not working meaning its taking the value however it is not changing the value..
# 4  
Old 01-22-2010
can you post the input data line from file demo..
# 5  
Old 01-22-2010
Here is what im getting
Code:
host$ cat demo
http-port = 80

host$ ./test2
enter value
81

host$ cat demo
http-port = 80

Filename:test2 has the code I posted earlier and it should change the http-port value in Filename:demo.


The value in the file:demo should be 81 after executing test2, which is not happening..

Thanks
CK

Last edited by Scott; 01-22-2010 at 05:53 PM.. Reason: Please use code tags
# 6  
Old 01-22-2010
Hi.

Based on your original sed:

Code:
sed "s/http-port = 80 /http-port = $ans/g" demo

all I can see that is wrong is a space before the / in the substitution part of your sed expression:

i.e. should be
Code:
sed "s/http-port = 80/http-port = $ans/g" demo

Code:
$ cat Test
ans=81
sed "s/http-port = 80 /http-port = $ans/g" demo
$ ./Test
http-port = 80

$ cat Test
ans=81
sed "s/http-port = 80/http-port = $ans/g" demo
$ ./Test
http-port = 81

# 7  
Old 01-22-2010
Yep, you are right.thank you sir, its working now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to find port number wwn of particular port on dual port HBA,?

please find the below o/p for your reference bash-3.00# fcinfo hba-port HBA Port WWN: 21000024ff295a34 OS Device Name: /dev/cfg/c2 Manufacturer: QLogic Corp. Model: 375-3356-02 Firmware Version: 05.03.02 FCode/BIOS Version: BIOS: 2.02; fcode: 2.01;... (3 Replies)
Discussion started by: sb200
3 Replies

2. UNIX for Advanced & Expert Users

Port number file

In which file inside the application code we can find the list of port numbers that the application is entitled to listen? (4 Replies)
Discussion started by: p_gautham12
4 Replies

3. Shell Programming and Scripting

sed inside sed for replacing string

My need is : Want to change docBase="/something/something/something" to docBase="/only/this/path/for/all/files" I have some (about 250 files)xml files. In FileOne it contains <Context path="/PPP" displayName="PPP" docBase="/home/me/documents" reloadable="true" crossContext="true">... (1 Reply)
Discussion started by: linuxadmin
1 Replies

4. IP Networking

Binding the port number.

Hi all, Application A is using an port number 100 and is binded to an interface 1. Application B is using an port number 100 and is binded to an interface 2. can we bind the two applications on same port number based on interfaces. what i want to know is two... (3 Replies)
Discussion started by: vijaypdp2006
3 Replies

5. Shell Programming and Scripting

Replacing the first 0 with a number

Hi, Appreciate any help in advance ;-) There are some numbers between 0 and 1, 0 not included: .2500, .3333, .5000, .6666, .7500, 1.000 How to replace the first 0 ( after the dot ) with a number, say, if the number is 3: .2500 will be .2530 .5000 will be .5300 .7500 will be .7530 ... (3 Replies)
Discussion started by: wanttolearn
3 Replies

6. Shell Programming and Scripting

Need help in finding and replacing port numbers.

Hi All, I am trying to write a shell script which firstly will search some files and then increase the port numbers mentioned in them by a certain no. let me clear it with an example- suppose there r few files a,b,c,d.... file a's content- <serverEntries xmi:id="ServerEntry_1"... (3 Replies)
Discussion started by: ankushsingh10
3 Replies

7. UNIX for Dummies Questions & Answers

port number

hi all i want to connect a system, how can i know the port number of a system. (2 Replies)
Discussion started by: tukuna82
2 Replies

8. UNIX for Dummies Questions & Answers

Need to know port number

Hi expert, I wanted to know in which port my apache is running in solaris box thanks Shaan (1 Reply)
Discussion started by: shaan_dmp
1 Replies

9. UNIX for Dummies Questions & Answers

how to know whether particular port number is free or not

I wish to know whether a particular port is free or not in my SUN solaris SPARC machine . I wish to use that particular port for one server software. How do I know that. (2 Replies)
Discussion started by: Hitesh Shah
2 Replies

10. Cybersecurity

get number of a port

Hello every one. I work in a LAN with many application server. Each one use a different port. What command permit to obtain the number of these port. thanks (2 Replies)
Discussion started by: hoang
2 Replies
Login or Register to Ask a Question