Thread: A weird question.

  1. #16
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    (I actually need the 'time' part, not the 'fps', but obviously that can be adapted easily.)
    Oops, my bad. I guess I'll leave determining the 'time' part "as an exercise for the reader."

    I think emacs is displaying those characters already (notice the ^M). The less command displays control characters nicely, too.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #17
    Registered User
    Join Date
    Jun 2009
    Posts
    9
    Cool, I didn't know about the -vet option in cat...

    Btw, I don't know perl at all really, anyone know how could I adapt that little script so that it picked out the numbers after "time=", even if they're greater than 3 digits?

  3. #18
    Registered User
    Join Date
    Jun 2009
    Posts
    9
    hehe, okay then, I got it to grab the numbers after time, but only 3 digits... I suppose I'll find myself a perl tutorial.

  4. #19
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by IanKoro View Post
    hehe, okay then, I got it to grab the numbers after time, but only 3 digits... I suppose I'll find myself a perl tutorial.
    "Regular expression" tutorial. They are not unique to perl. There is a regex.h for C that will permit you to do the same thing.

    That said, the thing I look at when I can't remember some regex syntax is here:
    Rex Swain's HTMLified Perl 5 Reference Guide
    G'bless Mr. Swain...
    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

  5. #20
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The (\d+) will match any number of digits. What you want is to also match the '.' character, I'm guessing. Since '.' means "match any character" in regular expressions, you have to escape it with a backslash. So the regular expression might become
    Code:
    .*time=\s*([\d\.]+)
    (Using square brackets means, "match any of the characters in here.")

    Perhaps this isn't the best application of regular expressions, but I usually prefer them to wading through a string with strchr, strstr, and sscanf.

    P.S. Nice regular expression reference . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Kind of a weird question
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 10-23-2003, 01:37 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Weird Question maybe
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-27-2001, 07:30 PM