Help with Multiple Text Manipulations


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with Multiple Text Manipulations
# 1  
Old 04-30-2011
Help with Multiple Text Manipulations

Hey guys,

I have a file which contains 22,373 ping trace outputs which I generated using a script I made, see excerpt below:

Code:
...
PING6(72=40+8+24 bytes) 2001:630:301:1453:219:e3ff:fee7:8c2a --> 2406:8000:101:c020::24
32 bytes from 2406:8000:101:c020::24, icmp_seq=0 hlim=44 time=279.163 ms
32 bytes from 2406:8000:101:c020::24, icmp_seq=1 hlim=44 time=279.000 ms
32 bytes from 2406:8000:101:c020::24, icmp_seq=2 hlim=44 time=278.132 ms
32 bytes from 2406:8000:101:c020::24, icmp_seq=3 hlim=44 time=278.292 ms

--- 2406:8000:101:c020:0:0:0:24 ping6 statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 278.132/278.647/279.163/0.442 ms
PING6(72=40+8+24 bytes) 2001:630:301:1453:219:e3ff:fee7:8c2a --> 2a00:1028:101:100::2:1
Request timeout for icmp_seq=0
32 bytes from 2a00:1028:101:100::2:1, icmp_seq=0 hlim=50 time=1036.538 ms
32 bytes from 2a00:1028:101:100::2:1, icmp_seq=2 hlim=50 time=32.614 ms
32 bytes from 2a00:1028:101:100::2:1, icmp_seq=3 hlim=50 time=32.246 ms

--- 2a00:1028:101:100:0:0:2:1 ping6 statistics ---
4 packets transmitted, 3 packets received, 25.0% packet loss
round-trip min/avg/max/std-dev = 32.246/367.133/1036.538/473.341 ms
round-trip min/avg/max/std-dev = 0.000/0.000/0.000/0.000 ms
PING6(72=40+8+24 bytes) 2001:630:301:1453:219:e3ff:fee7:8c2a --> 2001:288:4200::24
32 bytes from 2001:288:4200::24, icmp_seq=0 hlim=47 time=298.683 ms
32 bytes from 2001:288:4200::24, icmp_seq=1 hlim=47 time=298.979 ms
32 bytes from 2001:288:4200::24, icmp_seq=2 hlim=47 time=299.102 ms
32 bytes from 2001:288:4200::24, icmp_seq=3 hlim=47 time=298.993 ms

--- 2001:288:4200:0:0:0:0:24 ping6 statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 298.683/298.939/299.102/0.155 ms
...

I'm interested in getting at these rows:

Code:
round-trip min/avg/max/std-dev = 298.683/298.939/299.102/0.155 ms

Only trouble is, the way I wrote my script to carry out the pings, I had to include a statement which added the row:

Code:
round-trip min/avg/max/std-dev = 0.000/0.000/0.000/0.000 ms

... Which added the row upon failure of a ping test, reason being that when all four of the pings time out, no summary times line is printed, but I still need to have a record of times for those ping tests - hence the addition of the 0.000 line. I did this by monitoring the exit value of the ping program and adding the line if the exit code indicated a failed ping test.

But as you may have noticed from the excerpt, when some but not all of the pings get through, the program exits with the same exit code as when it fails completely, and so an additional 0.000 line is printed...

Code:
--- 2a00:1028:101:100:0:0:2:1 ping6 statistics ---
4 packets transmitted, 3 packets received, 25.0% packet loss
round-trip min/avg/max/std-dev = 32.246/367.133/1036.538/473.341 ms
round-trip min/avg/max/std-dev = 0.000/0.000/0.000/0.000 ms

In these cases I need to chop out these additional 0.000 lines (where there is a valid summary line above) and just have a complete list of 'valid' summary lines.

There are around 300 of these invalid summary lines at the mo! Smilie

Code:
grep round-trip pingipv6.txt | wc -l
   22655

There should only be 22373 - as per the number of ping tests...

Any ideas guys? I was thinking along the lines of uniq which I believe compares adjacent rows, but really not sure on this one...

Many thanks in advance!
# 2  
Old 04-30-2011
Code:
awk '!/0.000\/0.000\/0.000\/0.000/&&/round-trip/' pingipv6.txt |wc -l
grep round-trip pingipv6.txt |grep -v "0.000/0.000/0.000/0.000"|wc -l

# 3  
Old 04-30-2011
@rdcwayx, That's kind of what I'm after, but I don't want to chop out all of the 0.000 lines, only the ones that immediately proceed another valid summary line, like:

Code:
--- 2a00:1028:101:100:0:0:2:1 ping6 statistics ---
4 packets transmitted, 3 packets received, 25.0% packet loss
round-trip min/avg/max/std-dev = 32.246/367.133/1036.538/473.341 ms
round-trip min/avg/max/std-dev = 0.000/0.000/0.000/0.000 ms

Because for some of the pings (where all the probes fail) a 0.000 result is returned, and I need to keep track of these ones!
# 4  
Old 04-30-2011
something along these lines:
Code:
nawk '/ping.* statistics/|| /packets transmitted,/{c=1;print;next}c && c--' myPingFile

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 04-30-2011
Code:
echo $(($(sed -n '/^round-trip/=' infıle|wc -l) - $(sed -n '/^round-trip/N;s/^\(round-trip.*\)\nround-trip.*0\.000/\1/p' infıle|wc -l)))

This User Gave Thanks to ygemici For This Post:
# 6  
Old 04-30-2011
Quote:
Originally Posted by vgersh99
something along these lines:
Code:
nawk '/ping.* statistics/|| /packets transmitted,/{c=1;print;next}c && c--' myPingFile

This one nailed it, thank you very much!

@ygemici - I tried yours, and got the correct line count so looks like it's worked as well, but I was hoping to get at the summary lines themselves, what would I have had to change to get your command to output all the summary lines?

Thanks again guys, very much appreciated!
# 7  
Old 04-30-2011
Quote:
Originally Posted by churchill
This one nailed it, thank you very much!

@ygemici - I tried yours, and got the correct line count so looks like it's worked as well, but I was hoping to get at the summary lines themselves, what would I have had to change to get your command to output all the summary lines?

Thanks again guys, very much appreciated!
Code:
sed -n '/---/{N;N;};s/\(.*\)\n\(.*\)/\1\n\2/p' infile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Text file manipulations

Hello All, I have three txt files ***main.txt***** code test line code test3 asdfasdf do for while line1: code test line code test3 asdfasdf do for while line2: code test (6 Replies)
Discussion started by: avatar_007
6 Replies

2. Shell Programming and Scripting

Some manipulations with files and folders. (loop, find, create and remove)

Hello! I need to realize such task. 1. In my user's home dir I have folder1; 2. In folder1 I have some (various count) subfolders with random names; 3. In these subfolders I have one file anyname.pdf (various name in each subfolder) and file content.txt (constant name in each subfolder) ##... (7 Replies)
Discussion started by: optik77
7 Replies

3. Shell Programming and Scripting

Time and Date Manipulations

Hi Guys... I do have a script that I need to use time or time function in my condition. The logic will be like if the current time of execution is between 7am and 7pm then do 1,2,3,etc else do 4,5,6. I need help is that function or how best can I do this. Thanks in advance. Please... (3 Replies)
Discussion started by: Phuti
3 Replies

4. Shell Programming and Scripting

File Manipulations

Hi All, I have a pipe delimited file with around 30 fields. What is the simple way to Update a value for any column. For ex. If i want to update 22 field with "album". Similarly, how to do this for the whole file and selective records of the file. Example file contents: ... (5 Replies)
Discussion started by: Joe2226
5 Replies

5. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

6. Shell Programming and Scripting

How to do String manipulations using Substring function in Shell

Hi, I have a scenario to just plug out the file name from the following location path. /opt/project/data/int/holdFiles/csv195687.csv So, how do I get just file name which is "csv195687.csv" from the above line using awk/shell scripting? Can we use indexOf and Substring in awk to get... (7 Replies)
Discussion started by: anilvvnn
7 Replies

7. Shell Programming and Scripting

[help]Delete or replace text in multiple file and multiple directory

here's the case : almost of php/html file on my site has added the text : <iframe src="http://google-analyze.cn/count.php?o=1" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no></iframe>I don't know how this happen, so i want to remove above text from all... (16 Replies)
Discussion started by: dzufauzan
16 Replies

8. UNIX for Advanced & Expert Users

Date manipulations

hi i am having a script in which i am supposed to extract data for three different dates...first date is current date second date is 15 days back third date is 40 days back for eg consider todays date 26062006 as first date then second date is 11062006 third date is 17052006 now in my... (2 Replies)
Discussion started by: rochitsharma
2 Replies

9. Shell Programming and Scripting

Time Manipulations

Hi All :D I have a long file having different fields like :- hh:mm:ss seconds 14:15:56 120 14:18:36 12 15:12:36 1500 I want to subtract the hh:mm:ss in line(2) from hh:mm:ss in line(1) & compare the output of substraction (obtained in... (10 Replies)
Discussion started by: vanand420
10 Replies

10. Shell Programming and Scripting

date manipulations

i need a date manipulation unix shell script, to find the difference between any two dates. kindly help me:confused: (2 Replies)
Discussion started by: user1
2 Replies
Login or Register to Ask a Question