1

I have a configuration file name movie.conf and i want to read a specific word in this file. The configuration file looks like this :

#This is a movie setting
#Read only the movie source

ffmpeg -f movie4linux2 -i /folder/movie1 -vcodec libx264 -preset ultrafast -tune zerolatency -s qvga -r 30 -qscale 5 -an -flags low_delay -bsf:v h264_mp4toannexb -maxrate 750k -bufsize 3000k -rfbufsize 300k -f h264

How can i only reads only the /folder/movie1 part by using regex? Can anybody show me how. I know using split can be done. But what if i want to use only regex on this? Any help would be much appreciated.

Rockster
  • 51
  • 1
  • 2
  • 9
  • Possible duplicate of http://stackoverflow.com/questions/23236840/retrieve-value-from-a-form-and-write-to-a-file – tripleee Apr 24 '14 at 05:52
  • The near-duplicate seems to be another student at the same course. It has multiple significant additional complexities which are not present in this question. – tripleee Apr 24 '14 at 05:57

4 Answers4

3
if (/^ffmpeg.*-i\s+(\S+)/) {
    print $1;
}
Miller
  • 34,962
  • 4
  • 39
  • 60
0
awk '/regex/ {print $5}' movie.conf

will serve your purpose I suppose

then you can pipe the result to check the regex you want.

suppose your file is :

ffmpeg -f movie4linux2 -i /folder/movie2 -vcodec libx264 -preset ultrafast -tune zerolatency -s qvga -r 30 -qscale 5 -an -flags low_delay -bsf:v h264_mp4toannexb -maxrate 750k -bufsize 3000k -rfbufsize 300k -f h264
ffmpeg -f movie4linux2 -i /folder/movie2 -vcodec libx264 -preset ultrafast -tune zerolatency -s qvga -r 30 -qscale 5 -an -flags low_delay -bsf:v h264_mp4toannexb -maxrate 750k -bufsize 3000k -rfbufsize 300k -f h264
ffmpeg -f movie4linux2 -i /folder/movie1 -vcodec libx264 -preset ultrafast -tune zerolatency -s qvga -r 30 -qscale 5 -an -flags low_delay -bsf:v h264_mp4toannexb -maxrate 750k -bufsize 3000k -rfbufsize 300k -f h264
ffmpeg -f movie4linux2 -i /folder/movie3 -vcodec libx264 -preset ultrafast -tune zerolatency -s qvga -r 30 -qscale 5 -an -flags low_delay -bsf:v h264_mp4toannexb -maxrate 750k -bufsize 3000k -rfbufsize 300k -f h264

list of 4 lines.

i use the command :

awk '/movie2/ {print $5}' sonew

output :

/folder/movie2
/folder/movie2
aelor
  • 10,892
  • 3
  • 32
  • 48
0

Rockster, this simple regex does the trick:

@result = $subject =~ m!/\w+!sg;
zx81
  • 41,100
  • 9
  • 89
  • 105
0

I can try this:

#!/usr/local/bin/perl
    #read the contents of movie.conf to $string
    open my $fh, '<', "movie.conf";
    read $fh, my $string, -s $fh; 
    close $fh;

    #match the movie path
    if ($string =~ m!(/.*?/\w+)!si) { 
        $result = $1;
    } else {
        $result = "";
    }
    print $result;
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268