0

I have a part of a script that isn't working as expected. It's supposed to take a list of newline-delimited episode paths in the format "/volume1/Shared Files/Cartoon/Show Name/Show Name SXX/file.mkv" (quotes included in the list file), run those files through mediainfo and append the UID to each line.

I can obtain the UID with the one-liner

/volume1/@appstore/nzbdrone/bin/mediainfo "/volume1/Shared Files/Cartoon/Show Name/Show Name SXX/file.mkv" | grep Unique | awk '{print $4}'

However, when executing the following code:

while read line; do
echo $line
/volume1/@appstore/nzbdrone/bin/mediainfo $line | grep Unique | awk '{print $4}' > $WorkingDir/output2.txt
echo `/volume1/@appstore/nzbdrone/bin/mediainfo $line | grep Unique | awk '{print $4}'`
var1=`echo /volume1/@appstore/nzbdrone/bin/mediainfo $line | grep Unique | awk '{print $4}'`
echo $var1
done < $WorkingDir/output.txt

I get the following output:

"/volume1/Shared Files/Cartoon/Show Name/Show Name SXX/file.mkv"


"/volume1/Shared Files/Cartoon/Show Name/Show Name SXX/file.mkv"


"/volume1/Shared Files/Cartoon/Show Name/Show Name SXX/file.mkv"


"/volume1/Shared Files/Cartoon/Show Name/Show Name SXX/file.mkv"


"/volume1/Shared Files/Cartoon/Show Name/Show Name SXX/file.mkv"


"/volume1/Shared Files/Cartoon/Show Name/Show Name SXX/file.mkv"

I know this wouldn't append the UIDs where I want, this is just an attempt at debugging. I'd expect at least one of those two blank lines between each echo $line would contain the UID. I don't know where it's going wrong :/

(running under bash on a Synology DS412+)

1 Answer 1

0

The double quotes are being read into the line variable and passed as part of the parameter to mediainfo. I never like using read for reading whole lines, preferring to use the line command instead.

You should remove the quotes from the input and instead use:-

while line=`line`; do
. . . . . .
/volume1/@appstore/nzbdrone/bin/mediainfo "$line" | grep Unique | awk '{print $4}' > $WorkingDir/output2.txt
. . . . . .

You should double-quote all instances of $line, not just in the line I have shown.

Note that line reads lines precisely, including the leading and trailing blanks which read strips.

3
  • Updated to: while line=line; do echo $line /volume1/@appstore/nzbdrone/bin/mediainfo "$line" | grep Unique | awk '{print $4}' > $WorkingDir/output2.txt echo /volume1/@appstore/nzbdrone/bin/mediainfo "$line" | grep Unique | awk '{print $4}'` var2=echo /volume1/@appstore/nzbdrone/bin/mediainfo "$line" | grep Unique | awk '{print $4}' echo $line echo $var2 done < $WorkingDir/output.txt` But I now get /volume1/Tom/Scripts/BaconSonarr/xseednzb-0.1.2.sh: line 25: line: command not found
    – boardwarp
    Commented Jan 10, 2015 at 14:20
  • I presume that your loop starts at the 25th line of your script. It looks like you don't have the line command installed: verify by typing type line or which line. In Ubuntu it is part of the util-linux package, installed by default. If you can't find it you can use head -n1 instead, so the first line becomes while line=$(head -n1); do (I have used $() notation to stop confusion with the back-quote for embedded code, but you can use back-quotes in your script).
    – AFH
    Commented Jan 10, 2015 at 15:35
  • This is running on a Synology, they're pretty sparse by default compared to a full distro. I tried the head -n1 first but it caused an infinite loop of empty lines. Next installed util-linux via ipkg, reverted to the code you originally suggested and it's working as expected! Thanks very much :)
    – boardwarp
    Commented Jan 11, 2015 at 4:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .