IP IS 10.238.48.225
spawn telnet 10.238.48.225
Trying 10.238.48.225...
Connected to 10.238.48.225.
Escape character is '^]'.
bgl-ras-bng-jnr-04
[bsnl.in]bgl-ras-bng-jnr-04#show sub sum all
--------------------------------------------------------------------------------
Total=10066
Type Authenticating Active Disconnecting
PPP 0 0 0
PPPoE 2 10064 1
DOT1Q 0 0 0
CLIPs 0 0 0
ATM-B1483 0 0 0
ATM-R1483 0 0 0
Mobile-IP 0 0 0
[bsnl.in]bgl-ras-bng-jnr-04#exit
Connection to 10.238.48.225 closed by foreign host.
IP IS 10.238.49.1
spawn telnet 10.238.49.1
Trying 10.238.49.1...
Connected to 10.238.49.1.
Escape character is '^]'.
chn-ras-bng-hdw-01
[local]chn-ras-bng-hdw-01#cont bsnl.in
[bsnl.in]chn-ras-bng-hdw-01#show sub sum all
--------------------------------------------------------------------------------
Total=7567
Type Authenticating Active Disconnecting
PPP 0 19 0
PPPoE 4 7544 5
DOT1Q 0 0 0
CLIPs 0 0 0
ATM-B1483 0 0 0
ATM-R1483 0 0 0
Mobile-IP 0 0 0
[bsnl.in]chn-ras-bng-hdw-01#exit
Connection to 10.238.49.1 closed by foreign host.
IP IS 10.238.49.33
spawn telnet 10.238.49.33
Trying 10.238.49.33...
Connected to 10.238.49.33.
Escape character is '^]'.
awk: syntax error near line 3
awk: illegal statement near line 3
awk: syntax error near line 3
awk: illegal statement near line 3
awk: illegal statement near line 4
awk: syntax error near line 5
awk: bailing out near line 5
root@blr-svr-oclan-01 #
What about Post #3? You might consider using /.local.|#cont/ as a search pattern if your awk flavour doesn't like the \[...\] construct.
And, as elixir_sinari pointed out (thank you!) , use gsub in lieu of sub.
root@blr-svr-oclan-01 # more script.awk
BEGIN {print "IP HOST_NAME SUB "}
/IP IS/ {IP=$3}
/.local.|#cont/ {HOST=$1;sub(/\[[^\]]*\]/,"",HOST);sub(/#.*/,"",HOST)}
/PPPoE/ {SUB=$3 ;print IP, HOST, SUB}
root@blr-svr-oclan-01 # /usr/xpg4/bin/awk -f script.awk /Scripts/sub_report.txt
IP HOST_NAME SUB
10.238.52.65 [local]pun-ras-bng-mhs-01 13623
10.238.54.1 [local]enk-ras-bng-cse-01 19610
10.238.56.225 [local]ngp-ras-bng-cto-01 19090
output is like below
if iam using only awk ,then output is like below
root@blr-svr-oclan-01 # awk -f script.awk /path/to/Scripts/sub_report.txt
awk: syntax error near line 3
awk: illegal statement near line 3
awk: syntax error near line 3
awk: illegal statement near line 3
awk: illegal statement near line 4
root@blr-svr-oclan-01 #