Sponsored Content
Top Forums Shell Programming and Scripting [Solved] How to increment and add variable length numbers to a variable in a loop? Post 302771034 by danish0909 on Tuesday 19th of February 2013 11:08:06 AM
Old 02-19-2013
Dears,

I have pasted some sample lines and highlighted the duration in bold:

Code:
0136530213AN019604609133GC0549465654          blackberry.net          20130219092609000001272               700000000172100130300000000000012120000121242003           000000000        20130219092609M2N8 0518557041297314243           11827013400000084.23.99.130    00000000000000000007000000000000000000000C00000101                                    0
0147200213AN019604509103GC0540246180          web2                    201302191009280000001410567302555     000000000123000000100000000000052700000527042003           000000000        20130219100928M2N8 0518546907805867587           28242021710000084.23.98.130    00000000000000501000000000000000000000000C23230301                                    0
0157650213AN019604509103GC0541471076          web2                    201302190926220000003030563880041     000000000100500000100000000000000000000000042003           000000000        20130219042619M2N8 05164473711405660658          60632070300000084.23.99.52     00000000000000501000000000000000000000000C23220301                                    0
0158110213AN019604609103GC0542371570          web2                    20130219102258000000101               700000010172100140300000010000046380000463842003           000000000        20130219102255M2N8 0518559338163034119           15216013260000084.23.99.134    00000000000000000007000000000000000000000C00000301                                    0
0172350213AN019604609103GC0564271836          web2                    20130219101346000018624               G00000205172100110800000205000002770000027742003           000000000        20130219092837M2N8 0518113891313183537           32174034330000084.23.99.15     00000000000000000104000000000000000000000C00000301                                    0
0173080213AN019604609132GC0568246272          blackberry.net          20130219095540000000001               700000000172100130300000000000010260000102642003           000000000        20130219095540M2N8 0518553727220908279           27201038030000084.23.99.14     00000000000000000007000000000000000000000C00000101                                    0
0188310213AN019604609132GC0569835060          blackberry.net          20130219082549000000133               700000000172100130300000000000013170000131742003           000000000        20130219072549M2N8 0517617595868822730           54733020370000084.23.99.53     00000000000000000007000000000000000000000C00000101                                    0
0189090213AN019604509113GC0548093306          wap2                    201302191012140000000310544554484     000000000120100000100000000000000250000002542003           000000000        20130219101214M2N8 0518555817805883875           53151021360000084.23.98.130    00000000000000501000000000000000000000000C23230101                                    0


Last edited by Corona688; 02-19-2013 at 12:24 PM.. Reason: modified code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

2. Shell Programming and Scripting

the given code goes in infinite loop and does not increment variable i

code is as #!/bin/sh i=1; while do welcome $i times; i='expr $i+1'; done exit 0; (6 Replies)
Discussion started by: mrityunjay22
6 Replies

3. Shell Programming and Scripting

how to add Loop number to variable name?

Hi there, I need to add a sequence of numbers to existing variables within the script to be able to call the variable automatically. Somehow it's just printing the loop number. Here's what I've got so far. :eek: #!/bin/sh FOLDER1=foo FOLDER2=bar FOLDER3=beer for ((a=1; a <= 3 ; a++))... (2 Replies)
Discussion started by: siul0_0
2 Replies

4. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

5. Shell Programming and Scripting

Increment of a variable

Hi All, I have a variable n that stores a number. Eg. echo $n comes out to be 120. I need to print 121 using echo command on n. Please advice. Thanks in advance !! (4 Replies)
Discussion started by: learning_skills
4 Replies

6. Shell Programming and Scripting

Split variable length and variable format CSV file

Dear all, I have basic knowledge of Unix script and her I am trying to process variable length and variable format CSV file. The file length will depend on the numbers of Earnings/Deductions/Direct Deposits. And The format will depend on whether it is Earnings/Deductions or Direct Deposits... (2 Replies)
Discussion started by: chechun
2 Replies

7. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

8. Shell Programming and Scripting

[Solved] Assigning a value to a variable name then running a loop on these values

Hi, I was wondering if anyone could assist me for (what is probably) a very straightforward answer. I have input files containing something like File 1 Apples Apples Apples Apples File 2 Bananas Bananas Bananas Bananas (4 Replies)
Discussion started by: hubleo
4 Replies

9. Shell Programming and Scripting

[SOLVED] UNIX FOR loop to read a variable with multiple values

Hi, I have a variable which stores file names as a result of find command. I need to delete all these files one by one, i.e. by a loop. Can anyone tell me how can it be done? The variable f2d has the file names like these abc.txt bcd.txt fff.txt gef.txt Now I have used a loop as... (12 Replies)
Discussion started by: jhilmil
12 Replies

10. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies
Time::Clock(3pm)					User Contributed Perl Documentation					  Time::Clock(3pm)

NAME
Time::Clock - Twenty-four hour clock object with nanosecond precision. SYNOPSIS
$t = Time::Clock->new(hour => 12, minute => 34, second => 56); print $t->as_string; # 12:34:56 $t->parse('8pm'); print "$t"; # 20:00:00 print $t->format('%I:%M %p'); # 08:00 PM $t->add(minutes => 15, nanoseconds => 123000000); print $t->as_string; # 20:15:00.123 $t->subtract(hours => 30); print $t->as_string; # 14:15:00.123 ... DESCRIPTION
A Time::Clock object is a twenty-four hour clock with nanosecond precision and wrap-around. It is a clock only; it has absolutely no concept of dates. Vagaries of date/time such as leap seconds and daylight savings time are unsupported. When a Time::Clock object hits 23:59:59.999999999 and at least one more nanosecond is added, it will wrap around to 00:00:00.000000000. This works in reverse when time is subtracted. Time::Clock objects automatically stringify to a user-definable format. CLASS METHODS
default_format FORMAT Set the default format used by the as_string method for all objects of this class. Defaults to "%H:%M:%S%n". See the documentation for the format method for a complete list of format specifiers. Note that this method may also be called as an object method, in which case it sets the default format for the individual object only. CONSTRUCTOR
new PARAMS Constructs a new Time::Clock object based on PARAMS, where PARAMS are name/value pairs. Any object method is a valid parameter name. Example: $t = Time::Clock->new(hour => 12, minute => 34, second => 56); If a single argument is passed to new, it is equivalent to calling the parse method. That is, this: $t = Time::Clock->new('12:34:56'); is equivalent to this: $t = Time::Clock->new; $t->parse('12:34:56'); Returns the newly constructed Time::Clock object. OBJECT METHODS
add PARAMS Add the time specified by PARAMS to the clock. Valid PARAMS are: "hours INT" An integer number of hours. "minutes INT" An integer number of minutes. "seconds INT" An integer number of seconds. "nanoseconds INT" An integer number of nanoseconds. If the amount of time added is large enough, the clock will wrap around from 23:59:59.999999999 to 00:00:00.000000000 as needed. ampm AM/PM Get or set the AM/PM attribute of the clock. Valid values of AM/PM must contain the letters "AM" or "PM" (case-insensitive), optionally followed by periods. A clock whose hour is greater than 12 cannot be set to AM. Any attempt to do so will cause a fatal error. Setting a clock whose hour is less than 12 to PM will cause its hour to be increased by 12. Example: $t = Time::Clock->new('8:00'); print $t->as_string; # 08:00:00 $t->ampm('PM'); print $t->as_string; # 20:00:00 Return the string "AM" if the hour is less than 12, "PM" otherwise. as_integer_seconds Returns the integer number of seconds since 00:00:00. as_string Returns a string representation of the clock, formatted according to the clock object's default_format. default_format FORMAT Set the default format used by the as_string method for this object. Defaults to "%H:%M:%S%n". See the documentation for the format method for a complete list of format specifiers. Note that this method may also be called as a class method, in which case it sets the default format all objects of this class. format FORMAT Returns the clock value formatted according to the FORMAT string containing "%"-prefixed format specifiers. Valid format specifiers are: %H The hour as a two-digit, zero-padded integer using a 24-hour clock (range 00 to 23). %I The hour as a two-digit, zero-padded integer using a 12-hour clock (range 01 to 12). %i The hour as an integer using a 12-hour clock (range 1 to 12). %k The hour as an integer using a 24-hour clock (range 0 to 23). %M The minute as a two-digit, zero-padded integer (range 00 to 59). %n If the clock has a non-zero nanosecond value, then this format produces a decimal point followed by the fractional seconds up to and including the last non-zero digit. If no nanosecond value is defined, or if it is zero, then this format produces an empty string. Examples: $t = Time::Clock->new('12:34:56'); print $t->format('%H:%M:%S%n'); # 12:34:56 $t->nanosecond(0); print $t->format('%H:%M:%S%n'); # 12:34:56 $t->nanosecond(123000000); print $t->format('%H:%M:%S%n'); # 12:34:56.123 "%[1-9]n" If the clock has a defined nanosecond value, then this format produces a decimal point followed by the specified number of digits of fractional seconds (1-9). Examples: $t = Time::Clock->new('12:34:56'); print $t->format('%H:%M:%S%4n'); # 12:34:56 $t->nanosecond(0); print $t->format('%H:%M:%S%4n'); # 12:34:56.0000 $t->nanosecond(123000000); print $t->format('%H:%M:%S%4n'); # 12:34:56.1230 %N Nanoseconds as a nine-digit, zero-padded integer (range 000000000 to 999999999) "%[1-9]N" Fractional seconds as a one- to nine-digit, zero-padded integer. Examples: $t = Time::Clock->new('12:34:56'); print $t->format('%H:%M:%S.%4N'); # 12:34:56.0000 $t->nanosecond(123000000); print $t->format('%H:%M:%S.%6N'); # 12:34:56.123000 $t->nanosecond(123000000); print $t->format('%H:%M:%S.%2N'); # 12:34:56.12 %p Either "AM" or "PM" according to the value return by the ampm method. %P Like %p but lowercase: "am" or "pm" %S The second as a two-digit, zero-padded integer (range 00 to 61). %s The integer number of seconds since 00:00:00. %T The time in 24-hour notation (%H:%M:%S). "%%" A literal "%" character. hour INT Get or set the hour of the clock. INT must be an integer from 0 to 23. minute INT Get or set the minute of the clock. INT must be an integer from 0 to 59. nanosecond INT Get or set the nanosecond of the clock. INT must be an integer from 0 to 999999999. parse STRING Set the clock time by parsing STRING. Valid string values contain an hour with optional minutes, seconds, fractional seconds, and AM/PM string. There should be a colon (":") between hours, minutes, and seconds, and a decimal point (".") between the seconds and fractional seconds. Fractional seconds may contain up to 9 digits. The AM/PM string is case-insensitive and may have periods after each letter. The string "now" will initialize the clock object with the current (local) time. If the Time::HiRes module is installed, this time will have fractional seconds. A time value with an hour of 24 and zero minutes, seconds, and nanoseconds is also accepted by this method. Here are some examples of valid time strings: 12:34:56.123456789 12:34:56.123 PM 24:00 8:30pm 6 A.m. now second INT Get or set the second of the clock. INT must be an integer from 0 to 59. subtract PARAMS Subtract the time specified by PARAMS from the clock. Valid PARAMS are: "hours INT" An integer number of hours. "minutes INT" An integer number of minutes. "seconds INT" An integer number of seconds. "nanoseconds INT" An integer number of nanoseconds. If the amount of time subtracted is large enough, the clock will wrap around from 00:00:00.000000000 to 23:59:59.999999999 as needed. AUTHOR
John C. Siracusa (siracusa@gmail.com) LICENSE
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-06-04 Time::Clock(3pm)
All times are GMT -4. The time now is 07:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy