Sponsored Content
Top Forums Shell Programming and Scripting Replacing lines between two files with awk Post 302308448 by rk4k on Saturday 18th of April 2009 10:12:30 AM
Old 04-18-2009
MySQL Replacing lines between two files with awk

Hello Masters,

I have two subtitles file with different language like below

First file :
Code:
1
00:00:41,136 --> 00:00:43,900
[<i># Underdog theme</i>]

2
00:00:55,383 --> 00:00:58,477
<i>[man] Ladies and gentlemen,</i>
<i>this is Simon Barsinister,</i>

3
00:00:58,553 --> 00:01:00,521
<i>the wickedest man in the world.</i>

4
00:01:00,588 --> 00:01:02,021
<i>He was evil and crazy.</i>

5
00:01:02,090 --> 00:01:06,026
<i>Simon and his wacky henchman, Cad,</i>
<i>schemed to rule the universe.</i>

6
00:01:06,094 --> 00:01:08,289
<i>But each time they were foiled by me,</i>

Second file :

Code:
1
00:00:35,060 --> 00:00:37,708
*** UNDERDOG ***

2
00:00:48,714 --> 00:00:51,668
Dame in gospodje,
to je Simon Barsinister,

3
00:00:51,745 --> 00:00:53,625    
najzlobnejši človek
na svetu.

4
00:00:53,701 --> 00:00:55,084
Bil je zloben in blazen.

5
00:00:55,160 --> 00:00:58,918
Simon in njegov sluga Cad
sta spletkarila proti univerzi.

6
00:00:58,994 --> 00:01:01,106
Ampak vedno sem jima
načrte prekrižal jaz,

I want to overwrite lines that contains time on first file with the apropriate lines from the second file so the final subtitles file will look like this :

Code:
1
00:00:35,060 --> 00:00:37,708
[<i># Underdog theme</i>]

2
00:00:48,714 --> 00:00:51,668
<i>[man] Ladies and gentlemen,</i>
<i>this is Simon Barsinister,</i>

3
00:00:51,745 --> 00:00:53,625    
<i>the wickedest man in the world.</i>

4
00:00:53,701 --> 00:00:55,084
<i>He was evil and crazy.</i>

5
00:00:55,160 --> 00:00:58,918
<i>Simon and his wacky henchman, Cad,</i>
<i>schemed to rule the universe.</i>

6
00:00:58,994 --> 00:01:01,106
<i>But each time they were foiled by me,</i>

How to do it with awk/gawk ?

TIA.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing lines in text files

Hi, I have 2 sets of text files. I need to take a field from a certain line in set 1 and put it in the same place in set b. The line appears once per file, in different places but is a set format and has the unique word "ANTENNA" in it and is always 81 characters long. Example from set a: ... (7 Replies)
Discussion started by: Jonny2Vests
7 Replies

2. Shell Programming and Scripting

replacing new lines in all files of a directory containing old lines

Hi all, I am trying to replace a few lines with other lines of all files in a directory which contain those few lines. say - there are some 10 files in a dir having the same 4 lines as 1.txt at the starting 1.txt line 1 line 2 line 3 line 4 ....................................... (1 Reply)
Discussion started by: rooster005
1 Replies

3. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

4. Shell Programming and Scripting

inserting and replacing lines with awk

Hello, I need to insert varying lines (i.e. these lines are an output of another script) between lines starting with certain fields. An example to make it more clear. This is the file where I wanna insert lines: (save it as "input.txt") ContrInMi_c_mir 2 10066 181014 200750... (12 Replies)
Discussion started by: tempestas
12 Replies

5. Shell Programming and Scripting

Help in replacing two blank lines with two lines of diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script... I used sed to search a line and insert two blank lines after the searchd line using the following sed command. sed "/data/{G;G;}/" filename . In the file, after data tag, two lines got inserted blank lines..... (4 Replies)
Discussion started by: arjun_arippa
4 Replies

6. UNIX for Dummies Questions & Answers

Finding lines with a regular expression, replacing them with blank lines

So the tag for this forum says all newbies welcome... All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed. Here's what I did come up with though: ... (2 Replies)
Discussion started by: Golpette
2 Replies

7. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

8. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum

Hi friends, This is sed & awk type question. It is slightly different from my previous question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers (but no more than 10 numbers in series) whenever i find it and produce an output file with the... (4 Replies)
Discussion started by: kaaliakahn
4 Replies

9. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

10. Shell Programming and Scripting

Replacing matched patterns in multiple files with awk

Hello all, I have since given up trying to figure this out and used sed instead, but I am trying to understand awk and was wondering how someone might do this in awk. I am trying to match on the first field of a specific file with the first field on multiple files, and append the second field... (2 Replies)
Discussion started by: karlmalowned
2 Replies
BOS_GETRESTRICTED(8)					       AFS Command Reference					      BOS_GETRESTRICTED(8)

NAME
bos_getrestricted - Displays whether a bos server is restricted or not SYNOPSIS
bos getrestricted -server <machine name> [-cell <cell name>] [-noauth] [-localauth] [-help] DESCRIPTION
The bos getrestricted command shows whether the server machine named by the -server argument is running in restricted mode. Restricted mode limits access to certain bos commands. See bos_setrestricted(8) for details of which commands are disabled by restricting a server. Use the bos setrestricted command to restrict, or un-restrict, a server. OPTIONS
-server <machine name> Indicates the server machine for which to display the restart times. Identify the machine by IP address or its host name (either fully- qualified or abbreviated unambiguously). For details, see bos(8). -cell <cell name> Names the cell in which to run the command. Do not combine this argument with the -localauth flag. For more details, see bos(8). -noauth Assigns the unprivileged identity "anonymous" to the issuer. Do not combine this flag with the -localauth flag. For more details, see bos(8). -localauth Constructs a server ticket using a key from the local /etc/openafs/server/KeyFile file. The bos command interpreter presents the ticket to the BOS Server during mutual authentication. Do not combine this flag with the -cell or -noauth options. For more details, see bos(8). -help Prints the online help for this command. All other valid options are ignored. OUTPUT
The output consists of a single line Restricted mode is <val> Where <val> is "on" or "off" PRIVILEGE REQUIRED
None SEE ALSO
KeyFile(5), bos(8), bos_setrestricted(8), COPYRIGHT
Copyright 2009 Simon Wilkinson <simon@sxw.org.uk> This documentation is covered by the BSD License as written in the doc/LICENSE file. This man page was written by Simon Wilkinson for OpenAFS. OpenAFS 2012-03-26 BOS_GETRESTRICTED(8)
All times are GMT -4. The time now is 02:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy