Extract terminal ip and port from line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract terminal ip and port from line
# 1  
Old 05-11-2012
Error Extract terminal ip and port from line

HI,

I have a line
Code:
 conn console {conntype=serial;connhost=122.25.000.220;connport=6038;password=123!}

and i am using the below code to extract the ip.
Code:
while read line
    do
        if echo "$line" | grep "connhost" >/dev/null 2>&1
        then
        echo $line
        TERM=`echo $line | awk -F\= '{print $3}'`
        break;
        fi
 done < "$HOME/input.txt"

echo "TERMINAL - $TERM"

Out put is
Code:
conn console {conntype=serial;connhost=122.25.000.220;connport=6038;password=123!}
TERMINAL - 122.25.000.220;connport

I need only IP and port, in two different variables, can you please enhance the script.
like below :
Code:
TERMINAL - 122.25.000.220
PORT - 6038

Thanks,
asak
# 2  
Old 05-11-2012
One way:
Code:
$ echo 'conn console {conntype=serial;connhost=122.25.000.220;connport=6038;password=123!}'|
awk -F'[}{=]' '/conn(host|port)/{print $NF}' RS=\;
122.25.000.220
6038

# 3  
Old 05-11-2012
HI Scrutinizer,

Thanks for your reply, but how to assign the values to two different variables.
ex:
Code:
TERMINAL - 122.25.000.220
PORT - 6038

Thanks,
asak
# 4  
Old 05-11-2012
Try:
Code:
read TERMINAL PORT << EOF
  $(awk -F'[}{=]' '/conn(host|port)/{print $NF}' RS=\; ORS=" " infile)
EOF

# 5  
Old 05-11-2012
You could use cut and eval...
Code:
$ line='conn console {conntype=serial;connhost=122.25.000.220;connport=6038;password=123!}'

$ eval $(echo $line|cut -d ';' -f2,3)

$ echo $connhost
122.25.000.220

$ echo $connport
6038

# 6  
Old 05-11-2012
Code:
read TERMINAL PORT <<< $(sed 's/.*host=\([^;]*\).*port=\([^;]*\).*/\1 \2/g' infile)

# 7  
Old 05-11-2012
Note: "<<<" works in bash/ksh93
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Process on a specified Terminal and Socket Port does not start

Hi, I new to AIX, and I have been using Rocket UniData in it. I had to set up a Process for Data Exchange by assigning a unique Terminal and a Socket Port to that process. I ran the process for the first time and it was successful and after use I stopped the process. Now when I want to run it... (3 Replies)
Discussion started by: BejoyS
3 Replies

2. IP Networking

Ssh port forwarding through a pseudo terminal

Here's a situation: I do all my work on a Mac. I have mysql installed on my mac. 1. There's a certain linux server 'server01' that provides access to another linux server 'server02' via a pseudo terminal So, to ssh into 'server02', I do this from my mac: ssh -t server01... (1 Reply)
Discussion started by: imperialguy
1 Replies

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

4. Shell Programming and Scripting

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"` stringC="PORT" echo ${stringA} echo ${stringB} echo ${stringC} position=`expr index "$stringB" "stringC"` echo... (2 Replies)
Discussion started by: jediwannabe
2 Replies

5. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

6. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

7. Shell Programming and Scripting

Extract Line and Column from CSV Line in ksh or bash format

Hi, I was doing some research and can't seem to find anything. I'm trying to automate a process by creating a script to read a csv line and column and assigning that value to a variable for the script to process it. Also if you could tell me the line and column if it's on another work ... (3 Replies)
Discussion started by: vpundit
3 Replies

8. Shell Programming and Scripting

need to extract terminal from this process -perl regx

Hi All, i ve a process, user4 31779 2836 0 01:43 pts/6 00:00:00 sh /home/user/DATE/SUT_SCR/c.sh like this i'll get so many process when in run ps -ef | grep pts | grep c.sh i need to extract terminal id from this string. i.e pts/6, or sometimes pts/22 same way i need to do for... (3 Replies)
Discussion started by: asak
3 Replies

9. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

10. Filesystems, Disks and Memory

terminal/port (serial) lock up mystery! SCO 5.0

Sorta new to Unix. great site here. I have SCO server with (5) 16 port Digi-boards and 5 line printers. For 3 years we've had no problems, till now... All of a sudden I get terminals and printers locking up. Killed the PID's for these particular situations. No help. So I disable the tty post... (10 Replies)
Discussion started by: ftn96
10 Replies
Login or Register to Ask a Question