Question

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.

Was it helpful?

Solution

if (/^ffmpeg.*-i\s+(\S+)/) {
    print $1;
}

OTHER TIPS

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

Rockster, this simple regex does the trick:

@result = $subject =~ m!/\w+!sg;

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top