LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-10-2013, 05:13 AM   #1
dr.x
Member
 
Registered: Jan 2013
Posts: 231

Rep: Reputation: Disabled
help with watch command with awk problem !


hi ,
if i use awk command without watch its fine
but if u use watch with awk it dont work
here is a an example :
watch --interval=5 "awk 'match($0,/http:\/\/[^/]+\//){_[substr($0,RSTART,RLENGTH)]=1}END{for (i in _) print i}' /home/p2"

im monitoring file /home/p2 ................ if i use :
"awk 'match($0,/http:\/\/[^/]+\//){_[substr($0,RSTART,RLENGTH)]=1}END{for (i in _) print i}' /home/p2"

it give me the output in the file , but i want to see the output of the file every 5 seconds by using watch command

i noted the problem in watch command , i saw the the command is changed :
here wt i mean
when i run the command
"awk 'match($0,/http:\/\/[^/]+\//){_[substr($0,RSTART,RLENGTH)]=1}END{for (i in _) print i}' /home/p2"

i see the screen
Every 5.0s: awk 'match(-su,/http:\/\/[^/]+\//){_[substr(-su,RSTART,RLENGTH)]=1}END{for (i in _) print i}' /home/p2


as u see above the $0 was changed with "-su" , i think this is the reason of my trouble

with to solve it

regards
 
Old 11-10-2013, 06:55 AM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
From 'man watch'
Quote:
Note that command is given to "sh -c" which means that you may need to use extra quoting to get the desired effect.
and from the Examples section of 'man watch'
Quote:
To see the effects of quoting, try these out

watch echo $$

watch echo '$$'

watch echo "'"'$$'"'"
It might be informative to try your example, and then inspect the output from 'ps ax' in another terminal while the example is running.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 12:46 AM
[SOLVED] watch with awk .... mythcat Linux - General 5 03-28-2012 04:40 AM
Problem Using If & For loop in AWK Command siramitsharma Programming 10 03-22-2012 06:35 PM
problem with awk command newtolinux78 Linux - Newbie 3 09-17-2010 08:17 AM
cat command space problem with awk in for loop. shan_nathan Programming 3 06-18-2009 05:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration