Gawk help (windows)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk help (windows)
# 1  
Old 02-22-2011
Gawk help (windows)

Someone help please. I tried to do it with findstr but I couldn't, so now I'm trying to output the following numbers from this text file with gawk (what I need is in bold down below):


Analyzing pool.ntp.org (1 of 1)...
delayoffset from local clock
Stratum: 2

Warning:
Reverse name resolution is best effort. It may not be
correct since RefID field in time packets differs across
NTP implementations and may not be using IP addresses.



pool.ntp.org[155.101.3.115:123]:
ICMP: 73ms
NTP: +0.0162516s RefID: 127-67-113-92.pool.ukrtel.net [92.113.67.127]


What I want to output is in bold. How can I do this with Gawk? With my noob knowledge I can only output:
Code:
+0.0162516s       RefID

But I would like to just have
Code:
0.0162516

Is this possible?
# 2  
Old 02-22-2011
I'm guessing that you're using something like...
Code:
$ awk -F: '$1=="NTP"{print $2}' file1
 +0.0162516s RefID

If so, then just add gsub...
Code:
$ awk -F: '$1=="NTP"{gsub(/[^0-9\.]*/,"",$2);print $2}' file1
0.0162516

# 3  
Old 02-22-2011
I appreciate the response.

The command I used was:
Code:
 gawk -F":" "/NTP/{print $2}" time.txt

I can't get your code to work, it is probably because I'm using "gawk for windows".. http://gnuwin32.sourceforge.net/packages/gawk.htm

When I use your code I get this response:
Image

Last edited by harris_t; 02-22-2011 at 03:32 AM..
# 4  
Old 02-22-2011
Escape the quotes like:
Code:
awk -F":" "$1==\"NTP\"{gsub(/[^0-9\.]*/,\"\",$2);print $2}" file

# 5  
Old 02-22-2011
Code:
echo "pool.ntp.org[155.101.3.115:123]:
ICMP: 73ms
NTP: +0.0162516s RefID: 127-67-113-92.pool.ukrtel.net [92.113.67.127]" |awk '/NTP/{print gensub(/(.*NTP: \+)(.*[0-9]s)
(Ref.*)/,"\\2",1,$0)}'
0.0162516s

# 6  
Old 02-22-2011
Thanks Franklin52 , but I just get a blank output. Smilie

---------- Post updated at 02:48 AM ---------- Previous update was at 02:46 AM ----------

I have no idea how to use your code yinyuemi lol.
# 7  
Old 02-22-2011
Code:
awk '/NTP/{print gensub(/(.*NTP: \+)(.*[0-9]s)(Ref.*)/,"\\2",1,$0)}' yourfile

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Gawk on Windows: Joining lines only if 1st field matches

Hi.. i have two files:: file_1:: mOnkey huMAnfile_2:: Human:hates:banana i:like:*** Monkey:loves:banana dogs:kill:catsdesired output:: Monkey:loves:banana Human:hates:bananaso only when the 1st field matches from both files print it from file_2 ((case-sensitive)) i also would like... (21 Replies)
Discussion started by: M@LIK
21 Replies

2. Windows & DOS: Issues & Discussions

Gawk Script in Windows batch file - Help

Good morning all. I have been running into a problem running a simple gawk script that selects every third line from an input file and writes it to an output file. gawk "NR%3==0" FileIn > FileOut I am attempting to run this command from a batch file at the command line. I have several hundred... (6 Replies)
Discussion started by: 10000springs
6 Replies

3. Shell Programming and Scripting

Gawk Help

Hi, I am using the script to print the portion of the file containing a particular string. But it is giving error "For Reading (No such file or directory). I am using cygwin as unix simulator. cat TT35*.log | gawk -v search="12345678" ' /mSOriginating /,/disconnectingParty/ { ... (1 Reply)
Discussion started by: vanand420
1 Replies

4. Shell Programming and Scripting

How can I make running gawk scripts more user-friendly in a Windows environment?

I know, and I apologise for using the W word, but I have users asking if they can use my gawk scripts, but I just know they're not going to like using the DOS command line. Is there any way for me to run my gawk scripts from a gui? Even if it's from a web page (html, php, what ever). I do not... (3 Replies)
Discussion started by: jonathanm
3 Replies

5. Shell Programming and Scripting

gawk HELP

I have to compare records in two files. It can be done using gawk/awk but i am unable to do it. Please help me File1 ABAAAAAB BC asa sa ABAAABAA BC bsa sm ABBBBAAA BC bxz sa ABAAABAB BC csa sa ABAAAAAA BC dsa sm ABBBBAAB BC dxz sa File 2 ABAAAAAB BC aas ba ABAAAAAB BC asa sa... (6 Replies)
Discussion started by: sandeep_hi
6 Replies
Login or Register to Ask a Question