Visit Our UNIX and Linux User Community

How to extract port number?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract port number?
# 1  
Old 02-04-2013
How to extract port number?

Hi my code is as follow:

stringA=`cat /s01/oracle/11.2/network/admin/listener.ora | grep "PORT"`
stringB=`cat $ORACLE_HOME/network/admin/listener.ora | grep "PORT"`

echo ${stringA}
echo ${stringB}
echo ${stringC}

position=`expr index "$stringB" "stringC"`

echo ${position}

output is as follow

But unfortunately I don't understand why position 7 is return and if position 7 is returned, I definitely cannot extract 1522 as port number, i.e. $port_number=1522

I'm running on Redhat 5.3

Red Hat Enterprise Linux Server release 5.3 (Tikanga)

# 2  
Old 02-05-2013
Here is another approach:
echo "Port Number = $stringB"


This User Gave Thanks to Yoda For This Post:
# 3  
Old 02-05-2013
Another way to get the port is by using grep -o:
grep -o PORT=[0-9]* file

Or by using perl:
perl -ne '/PORT=([0-9]*)/; print $1' file

Last edited by Subbeh; 02-05-2013 at 04:51 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #580
Difficulty: Easy
A file is a block of data used for storing information.
True or False?

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. Shell Programming and Scripting

Extract terminal ip and port from line

HI, I have a line conn console {conntype=serial;connhost=;connport=6038;password=123!} and i am using the below code to extract the ip. while read line do if echo "$line" | grep "connhost" >/dev/null 2>&1 then echo $line TERM=`echo... (8 Replies)
Discussion started by: asak
8 Replies

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

4. Solaris

Finding port number !!

Hi all , I want know the port no on which a particular application is running. How to find that? Thanks in anticipation (11 Replies)
Discussion started by: kumarmani
11 Replies

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

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

7. Shell Programming and Scripting

port number as an argument

What is the script that takes a port number as parameter and displays status, whether it is available or is already used by other process pls help (1 Reply)
Discussion started by: saikiran
1 Replies

8. UNIX for Advanced & Expert Users

FTP Port Number

On HP-UX 11 how do I get the port number of an active ftp connection? (2 Replies)
Discussion started by: mbb
2 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

Featured Tech Videos