Search code examples
macosbashcsvmediainfo

Some mediainfo output is being cut when echoing to file in bash OS X


If I use the following terminal command:

Mediainfo --Language=raw --Full '--Inform=General;%FileSize_String4%' '/Volumes/New Volume//FILM/test.avi'

I receive this output, which is what I want:

701.5 MiB

When I run this bash script in OS X:

find "$1" -name "*.avi" -o -name "*.AVI"| (

while IFS= read -r file; do

    vsize=($(Mediainfo --Language=raw --Full --Inform=General\;\%FileSize_String4\% "$file"))
    echo "$file","$vsize" >> /Users/me/fileaudit.csv 
done
)

I receive this output (the MiB/Gib etc is stripped):

701.5

What am I doing wrong?


Solution

  • I think you need to remove the outer parentheses where you assign the value to your variable size, so it looks like this:

    vsize=$(Mediainfo --Language=raw --Full --Inform=General\;\%FileSize_String4\% "$file")
    

    By the way, you can also get the file size in bytes of a file on OSX with:

    stat -f "%z" someFile