Quote:
It looks interesting! I'll try that. The thing I thought up is really basic and I would love to use grep!
|
I've written up a small guide of what the one-liner does
Code:
while read i
do
echo "$(ffprobe -i "$i" 2>&1 | egrep -o 'bitrate: [0-9]{1,3} .{4}' | cut -d' ' -f2-3)" "$i"
done < <(find . -type f \( -iname \*.ogg -o -iname \*.mp3 \))
This creates the while loop. for each line in the
file do something. Each line is represented by variable
i in this case
Code:
while read i; do something; done < file
This writes out to the screen the output of "$(commands)" and "$i". A good way of understanding $() is
echo $(ls), this will echo out the current files in your directory in a single echo statement. $i represents the current line in the while loop.
Code:
echo "$(commands)" "$i"
This takes ffprobe and outputs all information about it to stdout. You may notice
2>&1. This means take the stderr and redirect it to stdout. This is critical since we will be piping the output! A lot of programs write their output to stdout but ffprobe is funny that way.
Code:
ffprobe -i "$i" 2>&1
This takes the stdin (input data) from ffprobe and matches a string starting with "
bitrate: ", then matches any numbers between 0 to 9 between 1 to 3 times. So 1 24 and 932 counts, but 32523 or 2352 does not. Then it matches any character with "." exactly 4 times (so fasd and fsa9 is fine, dd is not).
It then pipes the output (with |) to cut
Code:
egrep -o 'bitrate: [0-9]{1,3} .{4}'
This sets the deliminator to whitespace so you can say. "I want fields 2 to 3. For example, if you had 3 blocks and assumed the space between each block was the deliminator, you can could say "I want blocks 2 through 3" by specifying field 2 through 3.
This is called "Process Substitution". Essentially, it writes the output of
commands to a special
FIFO or named pipe file so that it may be used by the while loop. More info ->
https://en.wikipedia.org/wiki/Named_pipe
This takes the current directory referenced as "
.", looks for only regular files (not FIFO's, directories, sockets, etc), then using \( \), makes a test then if either the file starts with .ogg or .mp3 (case insensitive) it will match
Code:
find . -type f \( -iname \*.ogg -o -iname \*.mp3 \)