Need a command to change the port region


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a command to change the port region
# 1  
Old 12-24-2013
Need a command to change the port region

Code:
portsuf=25
port=20925

I need to replace 09 with 25

It should be like 22525.

Can some please help with command or script.

Last edited by Scott; 12-24-2013 at 02:49 AM.. Reason: Please use code tags
# 2  
Old 12-24-2013
Quote:
Originally Posted by bhas85
portsuf=25
port=20925

I need to replace 09 with 25

It should be like 22525.

Can some please help with command or script.


Try :


Code:
$ echo "port=20925" | awk  'sub(substr($1,7,2),portsuf,$1)' portsuf=25
port=22525

Code:
$ echo "port=20925" | awk  '{print substr($1,1,6) portsuf substr($1,9)}' portsuf=25
port=22525

following will replace 09 with some string irrespective of their position, meaning wherever 09 it finds it will be replaced with string specified.
Code:
$ echo "port=20925" | sed 's/09/25/g'
port=22525


Last edited by Akshay Hegde; 12-24-2013 at 01:48 AM.. Reason: more detail
# 3  
Old 12-24-2013
Sorry i didn't gave you the full details what i required.Can you please see the below requirement what exactly i need.

portsuf and port variables are not constant.It varies everytime.

i will grep the below line from file
line=leprechaun.host.uri.list=raft://rt930test.info53.com:23025


I will enter the the value RT925 through command line--> from this i took 25 and and also port from the line

portsuf=25 --->this will varies what the parameters i am passing from command line
and port=23025 --> this i will take from file.It also varies.

The command should replace and get it as port_current=22525
# 4  
Old 12-24-2013
Try something like this

Code:
#!/bin/bash

line=leprechaun.host.uri.list=raft://rt930test.info53.com:23025
echo $line
printf "Enter New Port : "
read port
line=$(echo $line | awk -F":" 'sub(substr($NF,2,2),newport,$NF)' OFS=":" newport=$port)
echo $line

Code:
$ bash test.sh
leprechaun.host.uri.list=raft://rt930test.info53.com:23025
Enter New Port : 25
leprechaun.host.uri.list=raft://rt930test.info53.com:22525

$ bash test.sh
leprechaun.host.uri.list=raft://rt930test.info53.com:23025
Enter New Port : 99
leprechaun.host.uri.list=raft://rt930test.info53.com:29925

# 5  
Old 12-24-2013
Hi Akshay,

Thanks a lot it working fine.

Regards,
vijay,
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

How to change from tty03 to tty00 serial port in AIX 5.x?

Hi, We use AIX 5.x, and we have an application that use the info from a server through a serial port tty00. Some days ago, we bought a new two port serial board, and the server assign this new ports as tty02 and tty03, and leaves tty00 and tty01 as unavailable. We cant modify the program and... (4 Replies)
Discussion started by: trevian3969
4 Replies

2. 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

3. AIX

Change lv REGION in HDISK1

Dears my rootvg is missed up i can not extend the /opt as soon as i try to extend the Filesystem its give me that there is not enough space . as there any way to change the REGION of the LVs in HDISK1 ? lspv -p hdisk0 hdisk0: PP RANGE STATE REGION LV NAME TYPE ... (8 Replies)
Discussion started by: thecobra151
8 Replies

4. Shell Programming and Scripting

Region between lines

How can I find the regions between specific lines? I have a file which contains lines like this: chr1 0 17388 0 chr1 17388 17444 1 chr1 17444 17599 2 chr1 17599 17601 1 chr1 17601 569791 0 chr1 569791 569795 1 chr1 569795 569808 2 chr1 569808 569890 3 chr1 569890 570047 4 ... (9 Replies)
Discussion started by: linseyr
9 Replies

5. UNIX for Advanced & Expert Users

Best practice - determining what region you are on

Hello all, I have a question about what you think the best practice is to determine what region you are running on when you have a system setup with a DEV/TEST, QA, and PROD regions running the same scripts in all. So, when you run in DEV, you have a different directory structure, and you... (4 Replies)
Discussion started by: Rediranch
4 Replies

6. Solaris

How To Change 5 port Ip Address Solaris?

Hello i'm newbie in solaris, anybody know how to change five port solaris 10? exmpe: bge0, bge1, bge2, etc. anybody can help me with the script implementasi... and logical how solaris work. thank so much:b: (2 Replies)
Discussion started by: yanto85
2 Replies

7. Red Hat

To change of port name in nmap

Hi, Is it possible to change the nmap port name: For eg: 21/tcp open ftp 53/tcp open domain 80/tcp open http 111/tcp open rpcbind 836/tcp open unknown 843/tcp open unknown 953/tcp open rndc I need to change the port number 836 unknown to the name of the... (4 Replies)
Discussion started by: gsiva
4 Replies

8. SCO

Change FTP port UnixWare

Hi there, I have a client who wants to FTP to his server (UW7.1.4). He don't wants to use the standard 21 port but a differtent port like 8210. I added an extra ftp1line in the /etc/services and /etc/inetd.conf as same as the original ftp line. Restarted TCP/IP but when I connect with an... (0 Replies)
Discussion started by: p.vvugt
0 Replies

9. UNIX for Advanced & Expert Users

stack region

how can i determine that what percentage of stack region is currently is used? (i am using tru64 unix) (2 Replies)
Discussion started by: yakari
2 Replies
Login or Register to Ask a Question