Shell - bash recherche dans un fichier texte

Résolu/Fermé
Thesmarch - 29 mars 2012 à 17:04
 Thesmarch - 30 mars 2012 à 15:24
Bonjour,



A partir d'un fichier test.txt :

Press [q] to stop, [?] for help
frame= 419 fps=0.0 q=0.0 size= 0kB time=00:00:13.98 bitrate= 0.0kbits/s dup=1 drop=0
black_start:16.5832 black_end:25.0917 black_duration:8.5085
frame= 909 fps=907 q=0.0 size= 0kB time=00:00:30.33 bitrate= 0.0kbits/s dup=1 drop=0
frame= 1282 fps=853 q=0.0 size= 0kB time=00:00:42.77 bitrate= 0.0kbits/s dup=1 drop=0
black_start:50.2168 black_end:50.9509 black_duration:0.734067
frame= 1735 fps=866 q=0.0 size= 0kB time=00:00:57.89 bitrate= 0.0kbits/s dup=1 drop=0
frame= 2184 fps=872 q=0.0 size= 0kB time=00:01:12.87 bitrate= 0.0kbits/s dup=1 drop=0
black_start:81.9819 black_end:87.4207 black_duration:5.43877
frame= 2671 fps=889 q=0.0 size= 0kB time=00:01:29.12 bitrate= 0.0kbits/s dup=1 drop=0
frame= 3088 fps=889 q=0.0 Lsize= 0kB time=00:01:43.03 bitrate= 0.0kbits/s dup=1 drop=0

video:0kB audio:0kB global headers:0kB muxing overhead -nan%
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)


Grace à un script en shell, j'aimerais obtenir un fichier texte de ce type la:

resultat.txt

N°1
black_start = 16.5832
black_end = 25.0917
black_duration:8.5085

N°2
black_start = 50.2168
black_end = 50.9509
black_duration:0.734067

N°3
black_start = 81.9819
black_end = 87.4207
black_duration:5.43877


J'ai deja regarder de la doc sur awk, sed, grep .. mais je parviens pas à obtenir quelque chose qui tiens la route.

Merci pour votre aide
A voir également:

2 réponses

zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
29 mars 2012 à 17:33
Salut,

$ cat plop 
Press [q] to stop, [?] for help
frame= 419 fps=0.0 q=0.0 size= 0kB time=00:00:13.98 bitrate= 0.0kbits/s dup=1 drop=0
black_start:16.5832 black_end:25.0917 black_duration:8.5085
frame= 909 fps=907 q=0.0 size= 0kB time=00:00:30.33 bitrate= 0.0kbits/s dup=1 drop=0
frame= 1282 fps=853 q=0.0 size= 0kB time=00:00:42.77 bitrate= 0.0kbits/s dup=1 drop=0
black_start:50.2168 black_end:50.9509 black_duration:0.734067
frame= 1735 fps=866 q=0.0 size= 0kB time=00:00:57.89 bitrate= 0.0kbits/s dup=1 drop=0
frame= 2184 fps=872 q=0.0 size= 0kB time=00:01:12.87 bitrate= 0.0kbits/s dup=1 drop=0
black_start:81.9819 black_end:87.4207 black_duration:5.43877
frame= 2671 fps=889 q=0.0 size= 0kB time=00:01:29.12 bitrate= 0.0kbits/s dup=1 drop=0
frame= 3088 fps=889 q=0.0 Lsize= 0kB time=00:01:43.03 bitrate= 0.0kbits/s dup=1 drop=0

$ awk 'BEGIN{i=0} /black_start/ { i++; gsub(/:/," = ",$1);gsub(/:/," = ",$2); printf "%s\n%s\n%s\n%s\n\n","N°"i,$1,$2,$3}' plop 
N°1
black_start = 16.5832
black_end = 25.0917
black_duration:8.5085

N°2
black_start = 50.2168
black_end = 50.9509
black_duration:0.734067

N°3
black_start = 81.9819
black_end = 87.4207
black_duration:5.43877

;-))
1
Aaaaah magnifique merci!

j'ai juste un petit probleme, pour mon post, j'avai juste mis une partie du fichier texte, et quand je le met en entier:

ffmpeg version 0.9.1.git Copyright (c) 2000-2012 the FFmpeg developers
  built on Mar 15 2012 15:29:50 with gcc 4.6.1
  configuration: 
  libavutil      51. 42.100 / 51. 42.100
  libavcodec     54. 10.100 / 54. 10.100
  libavformat    54.  2.100 / 54.  2.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 64.101 /  2. 64.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  7.100 /  0.  7.100
Input #0, avi, from 'prjt_multi.avi':
  Metadata:
    encoder         : Lavf53.3.0
  Duration: 00:01:43.00, start: 0.000000, bitrate: 1808 kb/s
    Stream #0:0: Video: mpeg2video (Main) (mpg2 / 0x3267706D), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 104857 kb/s, 29.97 fps, 29.97 tbr, 29.97 tbn, 59.94 tbc
    Stream #0:1: Audio: mp2 (P[0][0][0] / 0x0050), 44100 Hz, 2 channels, s16, 128 kb/s
[buffer @ 0x90b60a0] w:720 h:480 pixfmt:yuv420p tb:1/1000000 sar:8/9 sws_param:
[blackdetect @ 0x8ff0c40] black_min_duration:0.1 pixel_black_th:0.100000 pixel_black_th_i:37 picture_black_ratio_th:0.700000
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf54.2.100
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video -> rawvideo)
Press [q] to stop, [?] for help
frame=  419 fps=0.0 q=0.0 size=       0kB time=00:00:13.98 bitrate=   0.0kbits/s dup=1 drop=0    
black_start:16.5832 black_end:25.0917 black_duration:8.5085
frame=  909 fps=907 q=0.0 size=       0kB time=00:00:30.33 bitrate=   0.0kbits/s dup=1 drop=0    
frame= 1282 fps=853 q=0.0 size=       0kB time=00:00:42.77 bitrate=   0.0kbits/s dup=1 drop=0    
black_start:50.2168 black_end:50.9509 black_duration:0.734067
frame= 1735 fps=866 q=0.0 size=       0kB time=00:00:57.89 bitrate=   0.0kbits/s dup=1 drop=0    
frame= 2184 fps=872 q=0.0 size=       0kB time=00:01:12.87 bitrate=   0.0kbits/s dup=1 drop=0    
black_start:81.9819 black_end:87.4207 black_duration:5.43877
frame= 2671 fps=889 q=0.0 size=       0kB time=00:01:29.12 bitrate=   0.0kbits/s dup=1 drop=0    
frame= 3088 fps=889 q=0.0 Lsize=       0kB time=00:01:43.03 bitrate=   0.0kbits/s dup=1 drop=0    

video:0kB audio:0kB global headers:0kB muxing overhead -nan%
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)


et que j'utilise : $ awk 'BEGIN{i=0} /black_start/ { i++; gsub(/:/," = ",$1);gsub(/:/," = ",$2); printf "%s\n%s\n%s\n%s\n\n","N°"i,$1,$2,$3}' output.txt

j'obtiens :

N°1
frame=
419
fps=0.0

N°2
frame=
909
fps=907

N°3
frame=
1735
fps=866


Et je comprends pas pourquoi parcequ'il n'y a pas d'autre "black_start" dans mon fichier texte complet?!

Merci encore zipe31!!
0
zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
29 mars 2012 à 18:09
Ton fichier il provient d'où ? Parce que chez moi même avec le dernier "copier/coller", le résultat est identique ;-\

Donc je suppute qu'il doit y avoir des caractères non-imprimables, style des retours chariots à la sauce M$ qui doivent mettre le bazar ;-(
0
Bah enfaite j'ai fais un script qui me permet d'analyser des fichiers .avi un par un et de me dire s'il y a des blackframes (écrans noir) ou non dans chacun de ces fichiers.
Pour détecter les blackframes j'utilise "ffmpeg"

Si tu a le courage je décris un peu plus en détail mon problème sur
http://www.developpez.net/forums/d1201671/systemes/linux/applications/shell/script-shell-sortie-standard/
Mais quoi qu'il en soit, merci pour ta réponse rapide ;)
0
zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
29 mars 2012 à 18:21
Peux-tu afficher le contenu de ton fichier output.txt avec la commande :

cat -A output.txt
0
lefebvre@lefebvre-VirtualBox:~/Bureau/Enregistrements/RESULTAT$ cat -A output.txt
ffmpeg version 0.9.1.git Copyright (c) 2000-2012 the FFmpeg developers$
  built on Mar 15 2012 15:29:50 with gcc 4.6.1$
  configuration: $
  libavutil      51. 42.100 / 51. 42.100$
  libavcodec     54. 10.100 / 54. 10.100$
  libavformat    54.  2.100 / 54.  2.100$
  libavdevice    53.  4.100 / 53.  4.100$
  libavfilter     2. 64.101 /  2. 64.101$
  libswscale      2.  1.100 /  2.  1.100$
  libswresample   0.  7.100 /  0.  7.100$
Input #0, avi, from 'prjt_multi.avi':$
  Metadata:$
    encoder         : Lavf53.3.0$
  Duration: 00:01:43.00, start: 0.000000, bitrate: 1808 kb/s$
    Stream #0:0: Video: mpeg2video (Main) (mpg2 / 0x3267706D), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 104857 kb/s, 29.97 fps, 29.97 tbr, 29.97 tbn, 59.94 tbc$
    Stream #0:1: Audio: mp2 (P[0][0][0] / 0x0050), 44100 Hz, 2 channels, s16, 128 kb/s$
[buffer @ 0x96610a0] w:720 h:480 pixfmt:yuv420p tb:1/1000000 sar:8/9 sws_param:$
[blackdetect @ 0x959bc40] black_min_duration:0.1 pixel_black_th:0.100000 pixel_black_th_i:37 picture_black_ratio_th:0.700000$
Output #0, null, to 'pipe:':$
  Metadata:$
    encoder         : Lavf54.2.100$
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 29.97 tbc$
Stream mapping:$
  Stream #0:0 -> #0:0 (mpeg2video -> rawvideo)$
Press [q] to stop, [?] for help$
frame=  337 fps=0.0 q=0.0 size=       0kB time=00:00:11.24 bitrate=   0.0kbits/s dup=1 drop=0    ^Mframe=  701 fps=700 q=0.0 size=       0kB time=00:00:23.39 bitrate=   0.0kbits/s dup=1 drop=0    ^Mblack_start:16.5832 black_end:25.0917 black_duration:8.5085$
frame=  978 fps=651 q=0.0 size=       0kB time=00:00:32.63 bitrate=   0.0kbits/s dup=1 drop=0    ^Mframe= 1438 fps=718 q=0.0 size=       0kB time=00:00:47.98 bitrate=   0.0kbits/s dup=1 drop=0    ^Mblack_start:50.2168 black_end:50.9509 black_duration:0.734067$
frame= 1908 fps=762 q=0.0 size=       0kB time=00:01:03.66 bitrate=   0.0kbits/s dup=1 drop=0    ^Mframe= 2195 fps=730 q=0.0 size=       0kB time=00:01:13.23 bitrate=   0.0kbits/s dup=1 drop=0    ^Mframe= 2426 fps=692 q=0.0 size=       0kB time=00:01:20.94 bitrate=   0.0kbits/s dup=1 drop=0    ^Mblack_start:81.9819 black_end:87.4207 black_duration:5.43877$
frame= 2690 fps=671 q=0.0 size=       0kB time=00:01:29.75 bitrate=   0.0kbits/s dup=1 drop=0    ^Mframe= 2902 fps=643 q=0.0 size=       0kB time=00:01:36.83 bitrate=   0.0kbits/s dup=1 drop=0    ^Mframe= 3088 fps=641 q=0.0 Lsize=       0kB time=00:01:43.03 bitrate=   0.0kbits/s dup=1 drop=0    ^M$
video:0kB audio:0kB global headers:0kB muxing overhead -nan%$
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)$
lefebvre@lefebvre-VirtualBox:~/Bureau/Enregistrements/RESULTAT$ 
0
zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
29 mars 2012 à 18:36
frame= 1908 fps=762 q=0.0 size= 0kB time=00:01:03.66 bitrate= 0.0kbits/s dup=1 drop=0 ^Mframe= 2195 fps=730 q=0.0 size= 0kB time=00:01:13.23 bitrate= 0.0kbits/s dup=1 drop=0 ^Mframe= 2426 fps=692 q=0.0 size= 0kB time=00:01:20.94 bitrate= 0.0kbits/s dup=1 drop=0 ^Mblack_start:81.9819 black_end:87.4207 black_duration:5.43877$

Il y a bien des caractères non-imprimables dans ton fichier.
Mais là ils ne sont pas effectifs, il me faudrait un exemple concret. Peux-tu mettre ton fichier sur Cjoint s'il te plaît ? Merci.
0