awk on non stop stream

This is a discussion on awk on non stop stream within the Linux Programming forums, part of the Platform Specific Boards category; Hello, I run an application which output is non-stop. Is it possible to use awk or something else to see ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    43

    awk on non stop stream

    Hello,

    I run an application which output is non-stop. Is it possible to use awk or something else to see only selected columns?

    thx

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You can script awk, so yes. You would write a script to process stdin, this could be done in any language, not just awk.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    43
    well i use
    Code:
     application | cut -f1 | awk {'print $1'}
    but it doesn't work. Why?

  4. #4
    Registered User
    Join Date
    Apr 2010
    Location
    Dublin, Ireland
    Posts
    4

    Smile Whats the ideal of the script?

    If u let me know what your trying to monitor with the awk script i can write u a one line perl script ??

    Newk

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    43
    well the ouput have 11 columns. I want only the 1,2,6,8,11.

  6. #6
    Registered User
    Join Date
    Apr 2010
    Location
    Dublin, Ireland
    Posts
    4

    awk script instead

    ok, as far as i can see from a few tests

    what u need is

    application | awk '{ print $1, $2, $6, $8, $11}'

    that should work

    Newk

  7. #7
    Registered User
    Join Date
    Apr 2010
    Posts
    43
    I tryed already, it doesn't work :/ maybe (?) because the applications output is non stop?

  8. #8
    Registered User
    Join Date
    Apr 2010
    Location
    Dublin, Ireland
    Posts
    4

    Need it in real-time?

    Do u need the formatted output as it comes out?? or wud after its run work too?

    Newky

  9. #9
    Registered User
    Join Date
    Apr 2010
    Posts
    43
    I need the formatted output as it comes out.. :/

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I'm forgetting my shell scripting, but what about something like
    Code:
    application& > temp_file
    while true; do tail temp_file | awk whatever; done

  11. #11
    Registered User
    Join Date
    Apr 2010
    Posts
    43
    can i do it without creating a file? is it possible something like that application | awk ... ?

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Pipe isn't going to pass anything along until the first process terminates, I'm pretty sure.

  13. #13
    Registered User
    Join Date
    Apr 2010
    Posts
    43
    dawm :/ i don't want to create a file because the stream is non-stop and if the application runs for a long time it'll create a huge file :/. There isn't something like the line-line buffer you suggested me before?

  14. #14
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You probably then want to redirect the output of your application to your script. Maybe something like
    Code:
    while true; do
        read var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11; #There's probably a shortcut for this
        echo "$var1 $var6 $var8 $var11";
    done

  15. #15
    Registered User
    Join Date
    Apr 2010
    Posts
    43
    the problem is that i call the application using popen inside a c program. Can i use something like that?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mistake of using awk
    By lehe in forum Linux Programming
    Replies: 6
    Last Post: 04-02-2009, 04:41 PM
  2. Closing a stream
    By cunnus88 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2008, 04:15 PM
  3. Help! About text stream and binary stream
    By Antigloss in forum C Programming
    Replies: 1
    Last Post: 09-01-2005, 08:40 AM
  4. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM
  5. Getting an input stream to stop creating a file
    By Stevek in forum C++ Programming
    Replies: 3
    Last Post: 03-21-2003, 03:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21