Python Cat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Python Cat
# 8  
Old 10-14-2014
Great, you have posted the input you have.

Now post the output you want. I'll work with what you posted meanwhile.
# 9  
Old 10-14-2014
Code:
$ cat pdp-active.awk

BEGIN {
        FS="[ \t\r:]+"
}

{ sub("^" FS, ""); }

/^(ccas-statistics|uplink|downlink|apn-radius-acct-server-statistics):/ {
        while( !($0 ~ "^" FS "$") ) {
                if(/tft-filter-count/) break;
                sub("^" FS, "");
                print
                if(getline != 1) break;
        }

        print ""
}

/pdp-active:/ { print $0"\n" }

$ awk -f pdp-active.awk test_expect.txt

pdp-active: 1219453

uplink:
packets: 5581950472180
bytes: 792988409784840
dropped-packets: 322643025207
packets-ipv6: 0
bytes-ipv6: 0
dropped-packets-ipv6: 317340352

downlink:
packets: 6356546278763
bytes: 5202689233327255
dropped-packets: 224502292039
packets-ipv6: 0
bytes-ipv6: 0
dropped-packets-ipv6: 0

pdp-active: 896591

uplink:
packets: 3485891928232
bytes: 512399111046839
dropped-packets: 318241658715
packets-ipv6: 0
bytes-ipv6: 0
dropped-packets-ipv6: 313917381

downlink:
packets: 4027201598702
bytes: 3078651754149495
dropped-packets: 222837858928
packets-ipv6: 0
bytes-ipv6: 0
dropped-packets-ipv6: 0

ccas-statistics:
ccas-identifier: DirectGy
ccas-start-request: 9062722155
ccas-start-request-failed: 138124458
ccas-update-request: 34654119968
ccas-update-request-failed: 14715326
ccas-stop-request: 8909036439
ccas-stop-request-failed: 23517853
ccas-user-service-denied: 516416544
ccas-user-unknown: 23056440
ccas-authorization-failure: 0
ccas-cc-not-applicable: 0

apn-radius-acct-server-statistics:
apn-radius-acct-server-address: 10.111.254.225
apn-radius-acct-requests-sent: 6339692763
apn-radius-acct-responses-received: 6330624775
apn-radius-acct-requests-timed-out: 9067987
apn-radius-acct-requests-retransmitted: 0
apn-radius-acct-invalid-authenticators-received: 0

apn-radius-acct-server-statistics:
apn-radius-acct-server-address: 10.111.254.226
apn-radius-acct-requests-sent: 6356302334
apn-radius-acct-responses-received: 6347847956
apn-radius-acct-requests-timed-out: 8454378
apn-radius-acct-requests-retransmitted: 0
apn-radius-acct-invalid-authenticators-received: 0

apn-radius-acct-server-statistics:
apn-radius-acct-server-address: 10.109.95.1
apn-radius-acct-requests-sent: 6352763779
apn-radius-acct-responses-received: 6341544445
apn-radius-acct-requests-timed-out: 11219323
apn-radius-acct-requests-retransmitted: 0
apn-radius-acct-invalid-authenticators-received: 69

apn-radius-acct-server-statistics:
apn-radius-acct-server-address: 10.109.95.2
apn-radius-acct-requests-sent: 6313912483
apn-radius-acct-responses-received: 6296608625
apn-radius-acct-requests-timed-out: 17303850
apn-radius-acct-requests-retransmitted: 0
apn-radius-acct-invalid-authenticators-received: 31

pdp-active: 314142

uplink:
packets: 2073810339890
bytes: 274003318141745
dropped-packets: 4004657993
packets-ipv6: 0
bytes-ipv6: 0
dropped-packets-ipv6: 3358345

downlink:
packets: 2299239432854
bytes: 2112912710702597
dropped-packets: 1612649642
packets-ipv6: 0
bytes-ipv6: 0
dropped-packets-ipv6: 0

ccas-statistics:
ccas-identifier: TSCCN2
ccas-start-request: 3359
ccas-start-request-failed: 3325
ccas-update-request: 2216
ccas-update-request-failed: 2
ccas-stop-request: 32
ccas-stop-request-failed: 0
ccas-user-service-denied: 0
ccas-user-unknown: 0
ccas-authorization-failure: 0
ccas-cc-not-applicable: 0

ccas-statistics:
ccas-identifier: DirectGy
ccas-start-request: 683192600
ccas-start-request-failed: 82961991
ccas-update-request: 9731908872
ccas-update-request-failed: 3170958
ccas-stop-request: 596751377
ccas-stop-request-failed: 250921
ccas-user-service-denied: 4245574
ccas-user-unknown: 17456139
ccas-authorization-failure: 0
ccas-cc-not-applicable: 0

$

This output should be much easier to load into any program since it's organized into blocks separated by one blank line, with consistent spacing and separators.

Last edited by Corona688; 10-14-2014 at 01:14 PM..
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 10-15-2014
Give us an example first line or two for each report. The rest is mechanical, unless report lines repeat headings, then give us 2 lines with a multiple child first hit. We could put each major item's elements into the environment using prefixed names in a subshell for every ':.*[^ ]' line and then pick the values for each report line to echo onto that report file.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies

2. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

4. SuSE

"ssh suse-server 'python -V' > python-version.out" not redirecting

Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here. I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
Discussion started by: Druonysus
3 Replies

5. Shell Programming and Scripting

CAT equivalent in python

cat is such a simple and useful command in UNIX. I was wonder if python had any equivalent. More specifically, I have a .txt file that I would like displayed from a python script. Is there a similar command besides "print?" When I try to use the print command, the text is formatted... (2 Replies)
Discussion started by: jl487
2 Replies

6. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

7. Shell Programming and Scripting

for i in `cat myname.txt` && for y in `cat yourname.txt`

cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat... (1 Reply)
Discussion started by: danimad
1 Replies

8. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies
Login or Register to Ask a Question