0

I'm trying to achieve the following:

I have a directory with multiple video files in it, I want to list all the files and in the same line add the duration and size of the file , using mediainfo (nothing else is available).

Mediainfo's output would be something like:

General
Format      : 
File Size   : 335 MiB
Duration    : 28mn 24s

I want to get the following data in a file:
filename : 335 MiB : 28mn 24s
So I can check if there are duplicates of the file...

Therefore I have the following script:

#!/bin/bash
         for i in $( ls /mnt/storage/kids/* ); do
                     echo -n item: $i ":"
                     mediainfo $i |grep -A 1 "File size"
                     done

with echo n I get the following line in the same line as item: $i and with grep -A 1 I get both file size and duration but duration goes into a second line isntead of the same as the file name and file size.
I would also like to get rid of file name and duration headers.

Any idea?

sorpigal
  • 25,504
  • 8
  • 57
  • 75
No Importa
  • 63
  • 1
  • 2
  • 4

2 Answers2

2

To get rid of the double line, change your code into:

echo -n item: $i ":" $(mediainfo $i |grep -A 1 "File size")

To get rid of the headers, you can use awk:

$ echo -e 'Filename : BOO\nSize : BAA' | awk -F: '{print $2}'
 BOO
 BAA
bos
  • 6,437
  • 3
  • 30
  • 46
  • Is the `-n` still necessary? I think not. The `-n` was there when OP didn't want a newline right after printing ":" – ArjunShankar Jun 26 '12 at 11:40
0
  • Don't use for i in $(ls), this is buggy. If you want to loop over files use for i in /mnt/storage/kids/* directly.
  • Avoid echo -n in favor of printf, which is portable.

Try this:

for i in /mnt/storage/kids/* ; do
    printf 'item: %s: ' "$i"
    mediainfo "$i" | sed -e '/File Size/,/Duration/{s/.*: //p;};d' | sed -e '$!N;s/\n/: /'
done
sorpigal
  • 25,504
  • 8
  • 57
  • 75