|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Script to get required output from textfile
Hi
Iam running below script on one text file. Code:
usr/xpg4/bin/awk 'BEGIN {print "IP HOST_NAME SUB "}
/IP IS/ {IP=$3}
/local/ {HOST=$1}
/PPPoE/ {SUB=$3 ;print IP, HOST, SUB}
' /Scripts/sub_report_$FILE>/Scripts/sub_final_report_.txtthe output is coming as below IP HTML Code:
HOST_NAME SUB 10.238.48.1 [local]bgl-ras-bng-bge-01#cont 12853 10.238.48.33 [local]bgl-ras-bng-bge-02#cont 9527 10.238.48.193 [local]bgl-ras-bng-jnr-03#cont 13475 10.238.48.225 [local]bgl-ras-bng-jnr-04#cont 10753 HTML Code:
IP HOST_NAME SUB 10.238.48.1 bgl-ras-bng-bge-01 12853 10.238.48.33 bgl-ras-bng-bge-02 9527 10.238.48.193 bgl-ras-bng-jnr-03 13475 10.238.48.225 bgl-ras-bng-jnr-04 10753 tnx in advance. Last edited by Scrutinizer; 02-11-2013 at 05:29 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Could you please paste a few lines from your input file for a sample?
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
What about adding
sub(/\[local\]|#cont/, "") to your awk program?
|
|
#4
|
||||
|
||||
|
Change Code:
/local/ {HOST=$1}to Code:
/local/ {HOST=$1;sub(/\[[^\]]*\]/,"",HOST);sub(/#.*/,"",HOST)}. Note that this is without looking at your input and just by looking at your output. It's always better to post input sample as balajesuri pointed out. @RudiC, that's a sub . So, it will do only 1 replacement if possible. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Hi
below are few lines from input file HTML Code:
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 '^]'. code HTML Code:
root@blr-svr-oclan-01 # awk 'BEGIN {print "IP HOST_NAME SUB "}
/IP IS/ {IP=$3}
/local/ {HOST=$1;sub(/\[[^\]]*\]/,"",HOST);sub(/#.*/,"",HOST)}
/PPPoE/ {SUB=$3 ;print IP, HOST, SUB}
'sub_report_20130210_10:00:00
HTML Code:
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 # |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
I didn't ask you to change
usr/xpg4/bin/awk to
awk .
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Hi
the script is working now but out put is not exactly as per requirement. HTML Code:
root@blr-svr-oclan-01 # /usr/xpg4/bin/awk 'BEGIN {print "IP HOST_NAME SUB "}
root@blr-svr-oclan-01 > /IP IS/ {IP=$3}
root@blr-svr-oclan-01 > /local/ {HOST=$1;sub(/\[[^\]]*\]/,"",HOST);sub(/#.*/,"",HOST)}
root@blr-svr-oclan-01 > /PPPoE/ {SUB=$3 ;print IP, HOST, SUB}
root@blr-svr-oclan-01 > ' sub_report_20130210_10:00:00
HTML Code:
IP HOST_NAME SUB 10.238.48.1 [local]bgl-ras-bng-bge-01 11165 10.238.48.33 [local]bgl-ras-bng-bge-02 8029 10.238.48.65 [local]bgl-ras-bng-bge-03 10364 10.238.48.97 [local]bgl-ras-bng-bge-04 11800 HTML Code:
IP HOST_NAME SUB 10.238.48.1 bgl-ras-bng-bge-01 12853 10.238.48.33 bgl-ras-bng-bge-02 9527 10.238.48.193 bgl-ras-bng-jnr-03 13475 |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script to mail monitoring output if required or redirect output to log file | aix_admin_007 | Shell Programming and Scripting | 4 | 10-22-2012 08:49 PM |
| Script to add text before the first word on a line in a textfile. | mjanssen | UNIX for Dummies Questions & Answers | 3 | 03-31-2011 03:53 AM |
| Regarding overwriting the textfile with output what we get! | smarty86 | Shell Programming and Scripting | 6 | 11-03-2009 08:09 AM |
| how to get the correct alignment in a textfile to a mail using shell script? | suman_dba1 | Shell Programming and Scripting | 1 | 04-06-2009 04:11 AM |
| Script required to get a required info from file. Pls. help me. | ntgobinath | Shell Programming and Scripting | 2 | 05-31-2008 08:34 AM |
|
|