Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Bash Script outputs to text file But it's not in alphabetical order?

  1. #1
    Join Date
    Jan 2011
    Beans
    52

    Bash Script outputs to text file But it's not in alphabetical order?

    Hello All,

    I have been trying to get this script to work properly and I have nearly given up. That is why I thought I would post here for some help. This is not my script, I found it on the internet and have tried to adapt it to my needs but am not having to much luck. I know there is some extra stuff in the script that I don't need but it runs sort of? I am not a scripter or coder by any means, getting a bit too old for that I think. The script runs but what I would like it to do is output to a text file in my home directory. It outputs now but the results are not in alphabetical order and I would like all the Artists to be printed from A-Z if this is possible. This script is going to scan my music library and retrieve the replaygain data from all of the flac tags. The reason I am trying to do this is because I am trying to use replay gain values to pick out tracks that are possibly clipped so I don't have to open every single file in audacity one by one. I have had about %60-%70 percent in being able to pick files that have some clipping on them. Unless someone has a better idea or a better way. I have around 700gig of flac files to check, so this will take awhile. Anyway here is the script and I hope someone can help sort this mess out. I thank all of you for any kind help in advance, I really appreciate it.


    Cheers,

    Singtoh

    Code:
    #!/bin/bash
    
    if [ ! -d "$1" ]
    then
        echo "Arg "$1" is NOT a directory!"
        exit $ARGUMENT_NOT_DIRECTORY
    fi
    
    flacnum=`ls "$1" | grep -c \\.flac`
    
    if [ $flacnum -lt 1 ]
    then
        echo $1" (No FLAC files, moving on)"
        exit 0
    else
        echo $1" ("$flacnum" FLAC files)"
    fi
    
        echo "Tag values:"
    flacfiles=`ls -1 "$1"/*.flac`
    IFS=$'\012'
    for file in $flacfiles
    do
        if [ ! -e "$file" ]
        then
        echo "Error: file "$file" not found."
        exit $FILE_NOT_FOUND
        fi
    
        echo $file
        metaflac --show-tag=ARTIST --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN --show-tag=REPLAYGAIN_ALBUM_PEAK "$file"
        exec 1>>/home/singtoh/rgvaluesM.txt
        
     done
    Attached Files Attached Files
    Last edited by CharlesA; November 29th, 2012 at 04:55 AM. Reason: added code tags

  2. #2
    Join Date
    Nov 2008
    Location
    Sheffield, UK
    Beans
    1,514
    Distro
    Ubuntu

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    could you post a little bit of the output your currently getting?

  3. #3
    Join Date
    Jan 2011
    Beans
    52

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    Hello SlugSlug,

    Thank you for the reply. This is a touch of what is outputting now:

    Code:
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2000-07-10 - Parachutes - Parlophone 527 7832 GB/10 Everything's Not Lost _ Life Is for Living.flac
    artist=Coldplay
    title=Everything's Not Lost / Life Is for Living
    REPLAYGAIN_TRACK_GAIN=-8.11 dB
    REPLAYGAIN_ALBUM_GAIN=-8.11 dB
    REPLAYGAIN_ALBUM_PEAK=0.99996948
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/02 In My Place.flac
    artist=Coldplay
    title=In My Place
    REPLAYGAIN_TRACK_GAIN=-8.67 dB
    REPLAYGAIN_ALBUM_GAIN=-8.67 dB
    REPLAYGAIN_ALBUM_PEAK=0.99996948
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/03 God Put a Smile Upon Your Face.flac
    artist=Coldplay
    title=God Put a Smile Upon Your Face
    REPLAYGAIN_TRACK_GAIN=-9.28 dB
    REPLAYGAIN_ALBUM_GAIN=-9.28 dB
    REPLAYGAIN_ALBUM_PEAK=0.99996948
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/04 The Scientist.flac
    artist=Coldplay
    title=The Scientist
    REPLAYGAIN_TRACK_GAIN=-8.72 dB
    REPLAYGAIN_ALBUM_GAIN=-8.72 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/05 Clocks.flac
    artist=Coldplay
    title=Clocks
    REPLAYGAIN_TRACK_GAIN=-8.85 dB
    REPLAYGAIN_ALBUM_GAIN=-8.85 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/06 Daylight.flac
    artist=Coldplay
    title=Daylight
    REPLAYGAIN_TRACK_GAIN=-9.00 dB
    REPLAYGAIN_ALBUM_GAIN=-9.00 dB
    REPLAYGAIN_ALBUM_PEAK=0.99996948
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/07 Green Eyes.flac
    artist=Coldplay
    title=Green Eyes
    REPLAYGAIN_TRACK_GAIN=-7.32 dB
    REPLAYGAIN_ALBUM_GAIN=-7.32 dB
    REPLAYGAIN_ALBUM_PEAK=0.99996948
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/08 Warning Sign.flac
    artist=Coldplay
    title=Warning Sign
    REPLAYGAIN_TRACK_GAIN=-7.63 dB
    REPLAYGAIN_ALBUM_GAIN=-7.63 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/09 A Whisper.flac
    artist=Coldplay
    title=A Whisper
    REPLAYGAIN_TRACK_GAIN=-9.58 dB
    REPLAYGAIN_ALBUM_GAIN=-9.58 dB
    REPLAYGAIN_ALBUM_PEAK=0.99996948
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/10 A Rush of Blood to the Head.flac
    The directory part /media/Storage/Music/Rock/ I don't need but couldn't seem to make it go away without making it log nothing??

    So if I could get the Artist into alphabetical order for a start would be nice or another idea I had would be to highlight all the numbers of REPLAYGAIN_TRACK_GAIN=-9.58 dB and REPLAYGAIN_ALBUM_GAIN=-9.58 dB to BOLD and RED all the way tru that go below say -4dB then I really wouldn't need to order it from A-Z. That would give me a visual cue of something to look at, then I could adjust that -4dB number to what works best for finding the clipped tracks, or even just have it log to a file anything that goes below -4dB according to REPLAYGAIN_TRACK_GAIN=-9.58 dB and REPLAYGAIN_ALBUM_GAIN=-9.58 dB or a given number, I don't know of the best way?? I ran this thru my library and its like 3000 pages long. I wish there was a program that say would open the flac files one by one, find clipping, close said track, log it to a file and then carry on all the way thru but I think that's a pipe dream?? Do you have any ideas possibly?? I guess it's a start if I can get it in order and/or highlighted in some way?? I just can't get my head around this scripting stuff. Thanks SlugSlug for the reply and hopefully some help

    Cheers,

    Singtoh
    Last edited by Singtoh; November 27th, 2012 at 12:39 PM. Reason: Added info

  4. #4
    Join Date
    Jan 2011
    Beans
    52

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    Hello All,

    This is what i have now which outputs to the text file better but it only prints the last bit of the file??

    Code:
    #!/bin/bash -u
    echo "You entered: '${*-}'"
    
    (
    if [ ! -d "$1" ]
    then
        echo "Arg "$1" is NOT a directory!"
        exit $ARGUMENT_NOT_DIRECTORY
    fi
    
    flacnum=`ls "$1" | grep -c \\.flac`
    
    if [ $flacnum -lt 1 ]
    then
        echo $1" (No FLAC files, moving on)"
        exit 0
    else
        echo $1" ("$flacnum" FLAC files)"
    fi
    
        echo "Tag Values Retrieved:"
    flacfiles=`ls -1 "$1"/*.flac`
    IFS=$'\012'
    for file in $flacfiles
    do
        if [ ! -e "$file" ]
        then
        echo "Error: file "$file" not found."
        exit $FILE_NOT_FOUND
        fi
    
    
        metaflac --show-tag=ARTIST --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN --show-tag=REPLAYGAIN_ALBUM_PEAK "$file"
    
        
    done) 2>&1 | tee rgainvaluesMUSIC.log
    And here is what is in the text file after I ctrl+c to stop it after a minute or so, it's just the last bit of info from rite before I hit ctrl+c???:

    /media/Storage/Music/Rock/REO Speedwagon - Original Album Classics - 5 CD Box Set/1978 - You Can Tune a Piano, But You Can't Tuna Fish - Epic JE35082 US (9 FLAC files)
    Tag Values Retrieved:
    artist=REO Speedwagon
    title=Roll With the Changes
    REPLAYGAIN_TRACK_GAIN=-7.88 dB
    REPLAYGAIN_ALBUM_GAIN=-8.52 dB
    REPLAYGAIN_ALBUM_PEAK=0.99893188
    artist=REO Speedwagon
    title=Time for Me to Fly
    REPLAYGAIN_TRACK_GAIN=-7.49 dB
    REPLAYGAIN_ALBUM_GAIN=-8.52 dB
    REPLAYGAIN_ALBUM_PEAK=0.99893188

    As I said, I am not a coder by any stretch,not even a little bit, just trying get something that works somewhat??

    Cheers,

    Singtoh

  5. #5
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    I haven't really read your script, but try

    Code:
    tee -a rgainvaluesMUSIC.log
    (a = append - the default for tee is to overwrite)

  6. #6
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    to print out track/album gains below -4
    Code:
    awk -v threshold=-4 '
          /[/]media[/]/ { file=$0 }
          /TRACK_GAIN/ { t_gain=$1; sub( /.*=/, "", t_gain ); }
          /ALBUM_GAIN/ { a_gain=$1; sub( /.*=/, "", a_gain ); }
          /ALBUM_PEAK/ { if (t_gain < threshold || a_gain < threshold) print file "\ntrack gain: " t_gain ", album gain: " a_gain; }
        ' in.txt
    i can only guess what you meant exactly though, your description of the problem is rather chaotic
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  7. #7
    Join Date
    Jan 2011
    Beans
    52

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    Quote Originally Posted by steeldriver View Post
    I haven't really read your script, but try

    Code:
    tee -a rgainvaluesMUSIC.log
    (a = append - the default for tee is to overwrite)
    Thanks Steeldriver. That let it print all 3000 pages of info. Now if I can narrow it down some I might win. I appreciate the help.

    Cheers,

    Singtoh

  8. #8
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    read post #6
    below -4.0 as in -5, -6... -9, etc?
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  9. #9
    Join Date
    Jan 2011
    Beans
    52

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    Quote Originally Posted by Vaphell View Post
    to print out track/album gains below -4
    Code:
    awk -v threshold=-4 '
          /[/]media[/]/ { file=$0 }
          /TRACK_GAIN/ { t_gain=$1; sub( /.*=/, "", t_gain ); }
          /ALBUM_GAIN/ { a_gain=$1; sub( /.*=/, "", a_gain ); }
          /ALBUM_PEAK/ { if (t_gain < threshold || a_gain < threshold) print file "\ntrack gain: " t_gain ", album gain: " a_gain; }
        ' in.txt
    i can only guess what you meant exactly though, your description of the problem is rather chaotic
    Hello Vaphell,

    Thanks for the reply. This is a snippet of what I get output with your code inserted to my script:

    artist=Queen
    title=Man on the Prowl
    REPLAYGAIN_TRACK_GAIN=-9.31 dB
    REPLAYGAIN_ALBUM_GAIN=-9.20 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=Machines (or 'Back to Humans')
    REPLAYGAIN_TRACK_GAIN=-9.16 dB
    REPLAYGAIN_ALBUM_GAIN=-9.20 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=I Want to Break Free
    REPLAYGAIN_TRACK_GAIN=-5.91 dB
    REPLAYGAIN_ALBUM_GAIN=-9.20 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=Keep Passing the Open Windows
    REPLAYGAIN_TRACK_GAIN=-9.39 dB
    REPLAYGAIN_ALBUM_GAIN=-9.20 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=Hammer to Fall
    REPLAYGAIN_TRACK_GAIN=-9.96 dB
    REPLAYGAIN_ALBUM_GAIN=-9.20 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=Is This the World We Created...?
    REPLAYGAIN_TRACK_GAIN=-4.59 dB
    REPLAYGAIN_ALBUM_GAIN=-9.20 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=I Go Crazy
    REPLAYGAIN_TRACK_GAIN=-9.17 dB
    REPLAYGAIN_ALBUM_GAIN=-9.01 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=I Want to Break Free (single remix)
    REPLAYGAIN_TRACK_GAIN=-8.14 dB
    REPLAYGAIN_ALBUM_GAIN=-9.01 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=Hammer to Fall (Headbanger's mix)
    REPLAYGAIN_TRACK_GAIN=-9.78 dB
    REPLAYGAIN_ALBUM_GAIN=-9.01 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=Is This the World We Created...? (live in Rio, January 1985)
    REPLAYGAIN_TRACK_GAIN=-6.46 dB
    REPLAYGAIN_ALBUM_GAIN=-9.01 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [
    awk: line 2: syntax error at or near ]
    artist=Queen
    title=It's a Hard Life (live in Rio, January 1985)
    REPLAYGAIN_TRACK_GAIN=-9.11 dB
    REPLAYGAIN_ALBUM_GAIN=-9.01 dB
    REPLAYGAIN_ALBUM_PEAK=1.00000000
    awk: line 2: regular expression compile failed (bad class -- [], [^] or [)
    [

    Sorry for the chaotic explanation Maybe I can be more clear. I am trying to scan the whole music library of around 700gig of flac files with this replaygain script and pick out high replaygain values, high meaning below -4dB(or I could change that number to what works best for finding clipping). So for instance a replaygain value of -10dB is most likely to have clipping on that track, and a replaygain value of -4dB is most likely to be clean. Then I can go to Audacity and fix it or if it's too bad, throw it out and re-rip the album. So if it prints only what is below i.e -4dB, I might only have to look at 2000 files instead of 8000. I don't know of another way to do this, but I think it's going to be a job to say the least I hope that is a bit more clearly put. I thank you very much Vaphell and Steeldriver for the help, I really appreciate it. I don't think I could ever wrap my head around this coding, it's giving me a headache

    Cheers,

    Singtoh

  10. #10
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash Script outputs to text file But it's not in alphabetical order?

    hm, works here on the test file... maybe try changing the pattern to this one in blue
    Code:
    $ awk -v threshold=-4 '
    >       /^\// { file=$0 }
    >       /TRACK_GAIN/ { t_gain=$1; sub( /.*=/, "", t_gain ); }
    >       /ALBUM_GAIN/ { a_gain=$1; sub( /.*=/, "", a_gain ); }
    >       /ALBUM_PEAK/ { if (t_gain < threshold || a_gain < threshold) print file "\ntrack gain: " t_gain ", album gain: " a_gain; }
    >     ' in.txt
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2000-07-10 - Parachutes - Parlophone 527 7832 GB/10 Everything's Not Lost _ Life Is for Living.flac
    track gain: -8.11, album gain: -8.11
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/02 In My Place.flac
    track gain: -8.67, album gain: -8.67
    /media/Storage/Music/Rock/Coldplay - Discography Lite/2002-08-26 - A Rush of Blood to the Head - Parlophone 540 5042 GB/03 God Put a Smile Upon Your Face.flac
    track gain: -9.28, album gain: -9.28
    ...
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •