- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: search for number and extract lines below
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 07:55 AM
тАО06-04-2009 07:55 AM
I would like to know how to extract all the timestamps to a separate file.
Solved! Go to Solution.
- Tags:
- missing attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 08:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 08:08 AM
тАО06-04-2009 08:08 AM
Re: search for number and extract lines below
grep "-->" myfile > timestamps
if you want to remove those timestamp lines and want the rest of the file, then:
grep -v "-->" myfile > mytrimmedfile
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 08:22 AM
тАО06-04-2009 08:22 AM
Re: search for number and extract lines below
So what i am trying to do here is to synchronize both my english and spanish subtitles with the same timestamp.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 10:23 AM
тАО06-04-2009 10:23 AM
Re: search for number and extract lines below
the construct should be something like this
last=1305
# get this number by manually editing the file
# and finding the last frame sequence
i=1
while [ $i -le $last ]
do
#source is spanish file target is english below
#find the line with timeframe
(( tfl=`grep -n ^$i\$ spanish|cut -d: -f1`+1 ))
#find the timeframe
spanish_time=`cat spa | sed "${tfl}!d"`
#using sed or another tool of your choice
#overwrite spanish_time into english file
#onto the same line
sed "${tfl}c\
${spanish_time}" english > /tmp/tempfile.tmp
#this line above has problems, most probably
#due to contents of variable spanish_time having
#special characters in it
#this is where you need to fiddle with sed man pages and books
mv /tmp/tempfile.tmp english
done # end of while loop
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 10:38 AM
тАО06-04-2009 10:38 AM
Re: search for number and extract lines below
Please help us help you.
The provided examples do NOT seem to line up.
My Spanish is almost non existent, but it seems to me that
Sp 12 = 00:02:18,942 --> 00:02:21,850
declarar culpable al acusado.
Corresponds with
En 11 : 00:02:01,350 --> 00:02:04,267
find the accused guilty.
And
Sp 13 = 00:02:21,935 --> 00:02:25,791
Sea cual sea su decisi├Г┬│n, su veredicto deber├Г┬б ser un├Г┬бnime.
Corresponds with
En 12 = 00:02:04,353 --> 00:02:08,220
However you decide, your verdict must be unanimous.
There NO match on the example times/sequence ever. Not even clos. The match on the simple number seems skewed by 1.
So... what is it? Bad examples?
Match regardsless?
Also... how much data can be expected?
For less than a million rows or so, a simple array can be build and files read in sequence.
For more rows, or for a more performant implementation you want an implementation which reads the files more or less in lock step, perhaps 'skipping' out of sequence records.
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 10:56 AM
тАО06-04-2009 10:56 AM
Re: search for number and extract lines below
What I had tried was:
given eng.txt and span.txt (provided "subtitle" files), and created eng.ts and span.ts using grep to extract the "-->" lines as outlined prev.
I pasted span.ts and eng.ts thusly:
paste -d"/" span.ts eng.ts > change.ts
adding "s/" to the beginning of each line , and "/" at end, you've a file you can use w/ sed to change span to eng ts
sed -f change.ts span.txt > changed.txt
BUT you have to remove singletons at the end of the file...as apparently their isn't a one-for-one correspondence of dialog stamps in the file.....
without some kind of correspondence, you can't rely on automated matching....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2009 12:18 PM
тАО06-04-2009 12:18 PM
Re: search for number and extract lines below
OK, as Hein said, the "timestamps" don't seem to match between files. However, if we use the first line of each paragraph as a key (your unique number), then we can substitute the contents of your Spanish file with your English one as below. If a key isn't represented in both files, nothing for that key will be reported.
# cat ./matchup
#!/usr/bin/perl
use strict;
use warnings;
my $file1 = shift or die "File1 expected\n";
my $file2 = shift or die "File2 expected\n";
die "Arguments must be files\n" unless -f $file1 && -f $file2;
my %frame;
{
local $/ = '';
my ( $fh, @a );
open( $fh, '<', $file1 ) or die "Can't open '$file1': $!\n";
while (<$fh>) {
@a = split /\n/;
push( @{ $frame{ $a[0] } }, () );
}
close $fh;
open( $fh, '<', $file2 ) or die "Can't open '$file2': $!\n";
while (<$fh>) {
@a = split /\n/;
if ( exists $frame{ $a[0] } ) {
push( @{ $frame{ $a[0] } }, @a[ 1 .. $#a ] );
}
}
}
for my $key ( sort keys %frame ) {
print join "\n", $key, @{ $frame{$key} }, "\n" if @{ $frame{$key} } > 0;
}
1;
...run as:
# ./matchup file1 file2
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-15-2009 07:30 AM
тАО06-15-2009 07:30 AM
Re: search for number and extract lines below
We will call you Spanish file Spanish.txt and English file English.txt. The goal is to replace the n'th time stamp in the Spanish file with the n'th time stamp in the English file. Mel Burslan rightly pointed out that n'th instance of --> indicates the n'th time stamp. OK so far.
# Read Spanish File into a str variable.
var str Spanish ; cat "Spanish.txt" > $Spanish
# Read English file into a str variable.
var str English ; cat "English.txt" > $English
# Count the instances of --> in Spanish.
var int count ; set $count = { sen "-->" $Spanish }
# Replace one by one.
var int n ; set $n=1
while ($n <= $count)
do
# Get the n'th time stamp from English.
var str timestamp ; set $timestamp = { stex -p -r ("^\n&-->&\n^"+makestr(int($n))) $English }
# Replance the n'th time stamp in Spanish with $timestamp (from English).
sal -r ("^\n&-->&\n^"+makestr(int($n))) $timestamp $Spanish
done
# Write $Spanish back to file.
echo $Spanish > "Spanish.txt"
Please test before using. I have not tested it. I have inserted comments, so you know what each line of the script is doing. Script is in biterscripting ( http://www.biterscripting.com ) .
Sen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-17-2009 03:33 AM
тАО06-17-2009 03:33 AM
Re: search for number and extract lines below
Something like this might work, it's untested thou.
Usage: ./script.sh filename.txt grep-pattern
#!/bin/bash
file=$1
grep=$2
tmp=$(cat -n $file | grep "$grep")
line=$(echo $tmp | awk '{print $1}'
total=$(wc -l $file)
tail=(($total - $line + 1))
head=10 # number of lines to show :)
tail -n+$tail $file | head -n$head
------
As i said, it's untested.
Best regards
Fredrik Eriksson