Find the answer to your Linux question:
Results 1 to 2 of 2
Hi all, I got stuck into a problem. I have a variable in which the data is stored as below: variable_test=0m0.001s 0m0.001s 0m0.001s 0m0.001s 0m0.001s 0m0.001s .....an so on. There ...
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Posts
    4

    parsing and storing multiple values using 'awk'

    Hi all,

    I got stuck into a problem. I have a variable in which the data is stored as below:

    variable_test=0m0.001s 0m0.001s 0m0.001s 0m0.001s 0m0.001s 0m0.001s .....an so on.

    There are lots of values in format like "3m1.057s" are stored in variable_test separated with an space between two such values.

    For exapmple, value is "3m1.057s"
    I need to save different parts of a value in three separate array variables such as
    the
    var_hour=3
    var_min=1
    var_sec= 057

    Can anyone tell if this can be done using "awk". A "WHILE" loop might be used to separate and store theses values I guess?
    Please help me out. Thanks

  2. #2
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    Sure it can be done. Use "m" as a seperator to get the hour, use "." to split the min sec parts, then drop the "s" at the end.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...