Help with Regular expression in ping script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Regular expression in ping script
# 1  
Old 11-01-2013
Help with Regular expression

Hi everyone,

Code:
ping  www.google.com | awk 'BEGIN{FS="[\= ]+";}{if ($10 ~ (/^[0-9][0-9]$/) || (/^[0-9][0-9]\.[0-9]?/)) print "SLOW"; else print $0}

output
Code:
awk: warning: escape sequence `\=' treated as plain `='
PING www.google.com (xxx.xxx.xxx.xxx) 56(84) bytes of data.
64 bytes from xxx.xxx.xxx.xxx icmp_req=2 ttl=128 time=23.4 ms
64 bytes from xxx.xxx.xxx.xxx: icmp_req=3 ttl=128 time=24.3 ms
64 bytes from xxx.xxx.xxx.xxx: icmp_req=4 ttl=128 time=23.0 ms

I have tested this reguler expression aganist normal input file and it works fine, however, piping ping to awk and it's not picking up the milisecond time to print out it's "SLOW"

What am i missing? Thanks in advance!!

Last edited by Apollo; 11-02-2013 at 06:55 AM..
# 2  
Old 11-01-2013
If there's two whole numbers before the decimal to qualify as "slow", does it matter if there's a decimal at all?

Code:
$ ping www.google.com | awk -F"[= ]" '{ print ($10 ~ /^[0-9][0-9]/)?"SLOW":$0 }'

(ps: thoughtful of you to hide Google's IP address Smilie)
This User Gave Thanks to Scott For This Post:
# 3  
Old 11-01-2013
Quote:
Originally Posted by Scott
If there's two whole numbers before the decimal to qualify as "slow", does it matter if there's a decimal at all?

Code:
$ ping www.google.com | awk -F"[= ]" '{ print ($10 ~ /^[0-9][0-9]/)?"SLOW":$0 }'

(ps: thoughtful of you to hide Google's IP address Smilie)
haha thanks man..

Do you mind to explain where did i go wrong with the actual reqular expression i have wrote? i would like to get your thoughts Smilie
# 4  
Old 11-01-2013
You were testing if $10 starts with two numbers, or if the whole line ($0) starts with two numbers and a decimal and another number.

Code:
$ echo a b c d e f g h i 1 | awk '$10 ~ /^1/ || $0 ~ /^2/'
a b c d e f g h i 1
$ echo a b c d e f g h i 2 | awk '$10 ~ /^1/ || $0 ~ /^2/'
$ echo 2 b c d e f g h i j | awk '$10 ~ /^1/ || $0 ~ /^2/'
2 b c d e f g h i j

This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed , awk script for printing matched line before regular expression

hi All , I am having a large file with lots of modules as shown below ############################################### module KKK kksd kskks jsn;lsm jsnlsn; Ring jjsjsj kskmsm jjs endmodule module llll 1kksd11 k232skks j33sn;l55sm (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

Help with awk script (syntax error in regular expression)

I've found this script which seems very promising to solve my issue: To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem. The passwords may or may not be contained within quotes, single quotes, etc. #!/bin/bash... (4 Replies)
Discussion started by: spacegoose
4 Replies

3. Shell Programming and Scripting

incorporating a regular expression statement in a shell script (.sh)

I do have a shell file where I call many unix commands . I would like to add a regular expression step in that shell file, where a text file, say Test.txt has to be openned and all the :'s should be replaced. Basically apply the follwoing regular expression: :%s/://g to that particular text... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

4. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

5. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

6. Shell Programming and Scripting

TCL Script Regular expression

Hi , I'm working on tcl script to extract specific data . I tried to use regular expression (new to regular expression) but I couldn't get it. here is a smaple of what I'm trying to extract from: + 20.167 0 1 cbr 500 ------- 2 5.0 1.3 3091 57612 d 20.167 0 1 cbr 500 ------- 2 5.0 1.3 3091... (1 Reply)
Discussion started by: ENG_MOHD
1 Replies

7. Shell Programming and Scripting

AWK Script Issue insert newline for a regular expression match

Hi , I am having an issue with the Awk script to insert newline for a regular expression match Having a file like this FILE1 #################### RXOER , RXERA , RXERC , RXERD .RXEA(RXBSN), RXERD , REXCD input RXEGT buffer RXETRY ####################### Want to match the RXE... (38 Replies)
Discussion started by: jaita
38 Replies

8. Shell Programming and Scripting

AWK script issue for the part regular expression

Hi I am having a file as shown below FILE 1 TXDD00, TXDD01, TXDD02, TXDD03, TXDD04, TXDD05, TXDD06, TXDD07, TXDD08, TXDD09, TXDD10, TXDD11, TXDD12, TXDD13, TXDD14, TXDD15, TXDD16, TXDD17, TXDD18, TXDD19, TXDDCLK, TXDJTAGAMPL0, TXDJTAGAMPL1,... (3 Replies)
Discussion started by: jaita
3 Replies

9. Shell Programming and Scripting

problem with Regular expression as input in shell script

Hi, I have script which will take a string as input and search in a file. But when I want to search a pattern which has special characters script is ignoring it. For example: I want to search a pattern "\.tumblr\.com". shell script is removing \ (backslah) and trying to search... (7 Replies)
Discussion started by: Anjan1
7 Replies

10. Shell Programming and Scripting

using regular expression an shell script!!

I want to check if the first argument of my shell script starts with a specifiec string? Any Idea?? Thank u (3 Replies)
Discussion started by: andy2000
3 Replies
Login or Register to Ask a Question