sed script to change timecode string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed script to change timecode string
# 1  
Old 03-31-2013
sed script to change timecode string

Need some help. I need to run a script to modify a csv file. Here is an example off a few lines from the csv

Code:
98M-01.WAV,98M,01,00:00:49,01:07:36:00,"MIX",,"BOOM-MKH50",,,,,,,,,,"",
98L-01.WAV,98L,01,00:00:51,01:01:45:00,"MIX",,"BOOM-MKH50",,,,,,,,,,"",

I need a sed script to find all timecode entries example 01:07:36:00 and change the the 3rd : into . For all instances of this pattern in the file
Change xx:xx:xx:xx to xx:xx:xx.xx
Thanks in advance!

Last edited by Scrutinizer; 03-31-2013 at 10:37 AM.. Reason: code tags
# 2  
Old 03-31-2013
An AWK solution:
Code:
awk -F, '
{
        for ( i = 1; i <= NF; i++ )
        {
                n = match( $i, /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/ )
                if ( n > 0 )
                        $i = substr ( $i, RSTART, RLENGTH - 3) "." substr ( $i, RSTART + RLENGTH - 2 )
        }
} 1 ' OFS=, file

# 3  
Old 03-31-2013
Appreciate the fast reply but the bash script editor on the ipad only takes sed
# 4  
Old 03-31-2013
This may be precise enough, you could try this:
Code:
sed 's/\(..:..:..\):/\1./g' file

# 5  
Old 03-31-2013
That did it! Thx!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using sed to change file into an awk script

Hi I want to use sed to change a text files input into an awk script. For example if the input says " chord -- english " I want to change this using sed 's/pattern 1 /pattern 2 /'g filename but I don't understand how to use part of the pattern 1 to input that into pattern 2 . Like after... (10 Replies)
Discussion started by: enforcer
10 Replies

2. UNIX for Beginners Questions & Answers

sed inside the awk script to replace a string in the array

The requirement is i need to find an array value matching with pattern {5:{ , replace that with 5: and reassign that to same array index and print it. I write something like below and the issue is sed command is not working. If i replace " with "`" the script gives syntax error.how can i... (8 Replies)
Discussion started by: bhagya123
8 Replies

3. Shell Programming and Scripting

Using sed to change values after a specific string

Hello I have a script that searches a file for a specific string and then changes the nth column after that string. I have searched online for how to do this with sed but have not seemed to find a solution that works for me. I am using bash. Some background info: - Currently I am using awk to... (4 Replies)
Discussion started by: prodigious8
4 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. Shell Programming and Scripting

Creating a sed script to change ip addresses in a file

So I'm new to this sed command and I am trying to create a script that replaces ip addresses when I name a file but can't tweak it to work. Here is what it looks like: #!/bin/bash # file=$1 # sed -e 's/-CPUaddr 10.30.10.166/-CPUaddr 10.30.10.151/g' -i "$file" sed -e 's/-CPUaddr... (10 Replies)
Discussion started by: uradunce
10 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

sed string manipulation in shell script

Hello, I have 1000 of sql queries and i need to push column value in query. e.g. SET INSERT_ID=1 INSERT INTO test (id,name) VALUES ('a'); SET INSERT_ID=2 INSERT INTO test (id,name) VALUES ('b'); SET INSERT_ID=3 INSERT INTO test (id,name) VALUES ('c'); SET INSERT_ID=4 INSERT INTO test... (12 Replies)
Discussion started by: mirfan
12 Replies

8. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

9. Shell Programming and Scripting

[Perl] Find one string, change another string.

Hi, In principle I am searching for a Perl equivalent for this sed command: sed "/TIM_AM_ARGS=/ s/60/1440/" $EDIT_FILE > $TEMP_FILE cp $TEMP_FILE $EDIT_FILE I was wondering if it needs to be like this, or that there other, shorter, alternatives: open (TIMENVFILE, "<$timenvfile") or die... (5 Replies)
Discussion started by: ejdv
5 Replies

10. Shell Programming and Scripting

Need shell/sed script for grep+string replacement

Hi, Let me explain the situation. There are many files in a directory and its sub-directories that conatin the string pattern "pa". I want to replace all such instances with the pattern "pranavagarwal" doing a grep "pa" `ls` does give me all the instances of the occurence of that... (3 Replies)
Discussion started by: pranavagarwal
3 Replies
Login or Register to Ask a Question