Increasing numbers in Column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Increasing numbers in Column
# 1  
Increasing numbers in Column

I have UWIn version of Unix for Desktop.
I have a file (Subtitle file of a movie) with the following format

[00:00:01]
abc def ghi jkl
[00:00:10]
mno pqr stuv
[00:00:15]
uvw xyz

The subtitles are delayed about a min or few seconds more. I want to increase it to be as shown below:
[00:01:11]
abc def ghi jkl
[00:01:20]
mno pqr stuv
[00:01:25]
uvw xyz

Can you please let me know, how to increase the numbers within "[...]"

Thanks
# 2  
Try...
Code:
$ cat file1
[00:00:01]
abc def ghi jkl
[00:00:10]
mno pqr stuv
[00:00:15]
uvw xyz

$ awk -F '[]:[]' '/^\[..:/{t=($2*60*60)+($3*60)+$4+s;$0=sprintf("[%02d:%02d:%02d]",t/60/60,t/60%60,t%60)}1' s=70 file1 > file2

$ cat file2
[00:01:11]
abc def ghi jkl
[00:01:20]
mno pqr stuv
[00:01:25]
uvw xyz

$

# 3  
I appreciate your help, Ygor.

I'm trying to understand the command. I haven't touched unix for almost a year and my knowledge drained little bit. Besides I was new to Unix even 2 years ago.

I understood the following
-F is a field separator. But how come "[]:[]" is a separator.
/^\[..:/ - replacing the string that begins with "[..:"; ".." - 2 characters.
s=70 - initialized for 70 seconds.

Can you please explain the command.
# 4  
"[]:[]" is a character set, see The AWK Manual - Regexp Operators and The AWK Manual - Field Separators

"/^\[..:/" Searches for lines that begin with "[..:" then executes the two commands within "{}". See The AWK Manual - Getting Started

"t=($2*60*60)+($3*60)+$4+s" This sets variable t to the new timestamp (in seconds). See The AWK Manual - Assignment Ops

"$0=sprintf("[%02d:%02d:%02d]",t/60/60,t/60%60,t%60)" Replaces current line with formatted timestamp. See The AWK Manual - Printf
# 5  
Thank you very much
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #425
Difficulty: Medium
C# 1.0 was first released in December 2002.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Adding Column Of Numbers

Hello. Trying to add a column of numbers and combine the 1st and 2nd fields as uniq with the new total. This works to add the numbers but can't figure an easy was to combine the 1st and 2nd column as the list is very long. awk '{s+=$3} END {print s}' bird dog 300 bird dog 100 cat clown 200... (1 Reply)
Discussion started by: jimmyf
1 Replies

2. Shell Programming and Scripting

AWK "make a new column that include increasing numbers"

please help!!!!!! I have a file .txt that has only one column like that: 34.1 35.5 35.6 45.6 ... Now, i want to add a column in the left in which the values of this column increase by 0.4 , for example: 0.0 34.1 0.4 35.5 0.8 35.6 1.2 45.6 How can i do with awk instructions??? ... (2 Replies)
Discussion started by: tienete
2 Replies

3. Shell Programming and Scripting

Adding patterns with increasing numbers at the end of every line

Hi All, I have a file which has some Linux commands in every line like more 456.dat more 3232.dat more 433.dat I want to add texts like this at the end of every line: more 456.dat > 1.txt more 3232.dat > 2.txt more 433.dat > 3.txt So, that the result of more goes into 1.txt... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. Shell Programming and Scripting

Add up a column of numbers

Given a file test.txt ,I can get a list of numbers in a single column using the command : cat test.txt | cut -d ' ' -f 8 that gives the output as 52 52 52 60 52 How can I get the sum of all the numbers in that column that is displayed? i want the output as sum=268 (4 Replies)
Discussion started by: hitha87
4 Replies

5. Shell Programming and Scripting

AWK processing -numbers to another column

Hi Guys, I'm trying to clean up my home logger file and can't seem to work this out. Here is my data: 10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 -49.1 220.9 10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9 10-19-2009 08:41 00.1 00.0 00.7 00.8 24.5 0.0... (2 Replies)
Discussion started by: BeJay
2 Replies

6. Shell Programming and Scripting

Changing values with increasing numbers!

Hi all, i have a command named "vmchange" and i must use it for thousands of data which must be changed. For example, vmchange -m N0001 vmchange -m N0002 vmchange -m N0003 ... ... vmchange -m N0100 How can i do that in awk or bash script? Any help would be greatly appreciated.. ... (5 Replies)
Discussion started by: oduth
5 Replies

7. Shell Programming and Scripting

How to add numbers in a column

Hi All thanks a lot for your previous replies. I need some help here. I am writing a script to test a machine for a thereshold. It is genrating the list of number that have to be added but not displaying the added value. The script is like this #!/bin/sh... (1 Reply)
Discussion started by: asirohi
1 Replies

8. Shell Programming and Scripting

Sub. numbers in column of output with If

This is my script. I am pulling the status of some hard where, but the status is in numerical form. The number 4 means Major and the 5 means Critical. In my script I would like to show the alarm type in aplha rather than numeric form. So if instead of seeing a 4 or 5 you would see MAjor or... (11 Replies)
Discussion started by: ja156194
11 Replies

9. UNIX for Advanced & Expert Users

Adding a column of numbers

Hello, I have a file, and one column has both positive and negative numbers. Does anyone know how I can calculate the total of all the values (i.e, +ve and -ve). eg: col1 col2 col3 data 23 data data 76 data data -30 data Thanks Khoom (1 Reply)
Discussion started by: Khoomfire
1 Replies

10. Shell Programming and Scripting

how to sum numbers in column

Hi, i want to sum all nubers in one column. Example: 12.23 11 23.01 3544.01 I'm trying to do this in awk, but it doesn't work properly. Seems like awk is summing only integers, for example: 12 11 23 3544 It cuts off numbers after dot. I used this command: akw /text/ file.txt |nawk... (1 Reply)
Discussion started by: iahveh
1 Replies

Featured Tech Videos