Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 31

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

  1. #11
    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
    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
    ...
    Hello Again Vaphell,

    This is a snippet of what I am getting after changing that:
    artist=Fleetwood Mac
    title=The City
    REPLAYGAIN_TRACK_GAIN=-2.05 dB
    REPLAYGAIN_ALBUM_GAIN=-2.05 dB
    REPLAYGAIN_ALBUM_PEAK=0.73333740
    awk: cannot open in.txt (No such file or directory)
    artist=Fleetwood Mac
    title=Miles Away
    REPLAYGAIN_TRACK_GAIN=-3.04 dB
    REPLAYGAIN_ALBUM_GAIN=-3.04 dB
    REPLAYGAIN_ALBUM_PEAK=0.91717529
    awk: cannot open in.txt (No such file or directory)
    artist=Fleetwood Mac
    title=Somebody
    REPLAYGAIN_TRACK_GAIN=-2.24 dB
    REPLAYGAIN_ALBUM_GAIN=-2.24 dB
    REPLAYGAIN_ALBUM_PEAK=0.93945312
    awk: cannot open in.txt (No such file or directory)

    So it's still printing higher(or is that lower) than -4dB and that other awk: ect.ect. A value less than -4dB going toward 0dB is a good thing and I don't need to print that and -4dB going towards -10dB is a bad thing and I do need to print that. Sorry, I get confused a bit on the higher/lower explanation I guess something in my script might be throwing it off maybe?? I don't have a clueThanks again Vaphell

    Cheers,

    Singtoh

  2. #12
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,399
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    obviously you should use your file rgainvaluesMUSIC.log instead of in.txt, that one was my dummy file for tests.

    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; }
         ' rgainvaluesMUSIC.log
    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

  3. #13
    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
    obviously you should use your file rgainvaluesMUSIC.log instead of in.txt, that one was my dummy file for tests.

    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; }
         ' rgainvaluesMUSIC.log
    Oooop's Sorry I sidn't see that one.

    I'll give it another look

  4. #14
    Join Date
    Jan 2011
    Beans
    52

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

    Quote Originally Posted by Singtoh View Post
    Oooop's Sorry I sidn't see that one.

    I'll give it another look
    Heres my script and the results of the las go, Vaphell

    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"
    
    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; }
        ' rgainvaluesMUSIC.log
    
        
    done) 2>&1 | tee -a rgainvaluesMUSIC.log
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)
    track gain: -1.12, album gain: -1.12
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)
    track gain: +1.09, album gain: +1.09
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)
    track gain: -0.27, album gain: -0.27
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)
    track gain: -3.49, album gain: -3.49
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)
    track gain: -1.85, album gain: -1.85
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)
    track gain: -1.39, album gain: -1.39
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)
    track gain: +0.10, album gain: +0.10
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)
    track gain: -0.94, album gain: -0.94
    /media/Storage/Music/Rock/U2 - Discography Lite/1993-07-05 - Zooropa - Nippon Phonogram PHCR-1750 JP (10 FLAC files)

    Sorry for the earlier mistake Vaphell.

    Cheers,

    Singtoh

  5. #15
    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
    obviously you should use your file rgainvaluesMUSIC.log instead of in.txt, that one was my dummy file for tests.

    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; }
         ' rgainvaluesMUSIC.log
    I guess I replied to my own post, please see the post above. I'm having a bad day I guess

    Cheers,

    Singtoh
    Last edited by Singtoh; November 28th, 2012 at 06:09 AM. Reason: misworded

  6. #16
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,399
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    run that awk once at the end, after the log file is filled with data, not every time you process a dir.
    Also if i am not mistaken, each run of the script appends to the file. Wont there be a boatload of redundant data in that file with every execution?


    How do you call that script exactly? i think that you could scan all flac files nicely with a single find command and then use awk similar to the one you have right now. probably 5 lines of code.

    edit:
    something like this
    Code:
    while IFS= read -rd $'\0' dr
      do metaflac --with-filename --show-tag=REPLAYGAIN_ALBUM_GAIN --show-tag=REPLAYGAIN_TRACK_GAIN "$dr"/*.flac
    done < <( find /media/Storage/Music/ -type d -print0 ) | awk 'BEGIN {FS="[ =]"}; $(NF-1)<-4 { print $0; }'
    Last edited by Vaphell; November 28th, 2012 at 07:22 AM.
    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. #17
    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
    run that awk once at the end, after the log file is filled with data, not every time you process a dir.
    Also if i am not mistaken, each run of the script appends to the file. Wont there be a boatload of redundant data in that file with every execution?


    How do you call that script exactly? i think that you could scan all flac files nicely with a single find command and then use awk similar to the one you have right now. probably 5 lines of code.

    edit:
    something like this
    Code:
    while IFS= read -rd $'\0' dr
      do metaflac --with-filename --show-tag=REPLAYGAIN_ALBUM_GAIN --show-tag=REPLAYGAIN_TRACK_GAIN "$dr"/*.flac
    done < <( find /media/Storage/Music/ -type d -print0 ) | awk 'BEGIN {FS="[ =]"}; $(NF-1)<-4 { print $0; }'
    Hello Vaphell,

    Sorry for the delay getting back, had to run an errand for the missus. I have been deleting that log file before every run of the script and this is how I call the script:

    Code:
    if [ ! -d "$1" ]
    then
        echo "Arg "$1" is NOT a directory!"
        exit $ARGUMENT_NOT_DIRECTORY
    fi
    
    echo "********************************************************"
    echo "Calling metadata.sh on each directory in:"
    echo $1
    echo ""
    find "$1" -type d -exec ~/metadata1.sh '{}' \;
    Tis is another script in the same directory I call with a bash alias. Yeah, I guess the way I am diong it is a bit convoluted, but I got the script off the internet and adapted it or tried to adapt it to my needs so there is stuff in the script that I am sure I don't need. Like I said I am not a coder, I'm just trying to cobble something together that works. So, I'll give the new code a try and see what happens and post again, the missus has gone to town so she won't be nagging in my ear for awhile. Thanks Vaphell

    Cheers,

    Singtoh

  8. #18
    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
    run that awk once at the end, after the log file is filled with data, not every time you process a dir.
    Also if i am not mistaken, each run of the script appends to the file. Wont there be a boatload of redundant data in that file with every execution?


    How do you call that script exactly? i think that you could scan all flac files nicely with a single find command and then use awk similar to the one you have right now. probably 5 lines of code.

    edit:
    something like this
    Code:
    while IFS= read -rd $'\0' dr
      do metaflac --with-filename --show-tag=REPLAYGAIN_ALBUM_GAIN --show-tag=REPLAYGAIN_TRACK_GAIN "$dr"/*.flac
    done < <( find /media/Storage/Music/ -type d -print0 ) | awk 'BEGIN {FS="[ =]"}; $(NF-1)<-4 { print $0; }'
    Ok Vaphell,

    This works:

    Code:
    #!/bin/bash -u
    echo "You entered: '${*-}'"
    
    (
    while IFS= read -rd $'\0' dr
      do metaflac --with-filename --show-tag=REPLAYGAIN_ALBUM_GAIN --show-tag=REPLAYGAIN_TRACK_GAIN "$dr"/*.flac
    done < <( find /media/Storage/Music/ -type d -print0 ) | awk 'BEGIN {FS="[ =]"}; $(NF-1)<-4 { print $0; }') 2>&1 | tee -a rgainvaluesMUSIC.log
    and it outputs this:

    /media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1999-11-23 - The Complete Blue Horizon Sessions 1967-1969 - Blue Horizon 73003-2 US/5-10 Sugar Mama (take 1).flac:REPLAYGAIN_ALBUM_GAIN=-4.26 dB
    /media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1999-11-23 - The Complete Blue Horizon Sessions 1967-1969 - Blue Horizon 73003-2 US/5-11 Sugar Mama.flac:REPLAYGAIN_ALBUM_GAIN=-4.26 dB
    /media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1999-11-23 - The Complete Blue Horizon Sessions 1967-1969 - Blue Horizon 73003-2 US/5-12 Homework.flac:REPLAYGAIN_ALBUM_GAIN=-4.26 dB
    /media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1999-11-23 - The Complete Blue Horizon Sessions 1967-1969 - Blue Horizon 73003-2 US/5-13 Honey Boy Blues.flac:REPLAYGAIN_ALBUM_GAIN=-4.26 dB
    /media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1999-11-23 - The Complete Blue Horizon Sessions 1967-1969 - Blue Horizon 73003-2 US/5-14 I Need Your Love (tak.flac:REPLAYGAIN_ALBUM_GAIN=-4.26 dB
    /media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1999-11-23 - The Complete Blue Horizon Sessions 1967-1969 - Blue Horizon 73003-2 US/5-14 I Need Your Love (tak.flac:REPLAYGAIN_TRACK_GAIN=-5.08 dB
    /media/Storage/Music/Rock/Fleetwood Mac - Discography Lite/1999-11-23 - The Complete Blue Horizon Sessions 1967-1969 - Blue Horizon 73003-2 US/5-15 Horton's Boogie

    so now I just have to make it output only ARTIST, ALBUM, REPLAYGAIN_TRACK_GAIN, and REPLAYGAIN_ALBUM_GAIN. The rest of it I don't need. So to clean things up a bit. I think I can make it do that. Your super super Vaphell, I really thank you very very big for your patience and help. This kinda stuff really does my head in Big headache

    Thanks again Vaphell I'll try and give this a go and see how I get on.

    Cheers Vaphell
    All the best,

    Singtoh

  9. #19
    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
    run that awk once at the end, after the log file is filled with data, not every time you process a dir.
    Also if i am not mistaken, each run of the script appends to the file. Wont there be a boatload of redundant data in that file with every execution?


    How do you call that script exactly? i think that you could scan all flac files nicely with a single find command and then use awk similar to the one you have right now. probably 5 lines of code.

    edit:
    something like this
    Code:
    while IFS= read -rd $'\0' dr
      do metaflac --with-filename --show-tag=REPLAYGAIN_ALBUM_GAIN --show-tag=REPLAYGAIN_TRACK_GAIN "$dr"/*.flac
    done < <( find /media/Storage/Music/ -type d -print0 ) | awk 'BEGIN {FS="[ =]"}; $(NF-1)<-4 { print $0; }'
    Hello Again Vaphell,

    I'm stuck. Here is the script I am using and the output that I am trying to achieve with your code to print only anything that is under -4dB:

    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 "$file"
    
    #while IFS= read -rd $'\0' dr
        #do metaflac --show-tag=ARTIST --show-tag=TITLE --show-tag=REPLAYGAIN_TRACK_GAIN --show-tag=REPLAYGAIN_ALBUM_GAIN "$dr"/*.flac 
        #done < <( -type d -print0 ) | awk 'BEGIN {FS="[ =]"}; $(NF-1)<-4 { print $0; }'
        
    done) 2>&1 | tee -a rgainvaluesMUSIC.log
    and some of the output that I would like to see:

    Tag Values Retrieved:
    artist=The Doobie Brothers
    title=Listen to the Music
    REPLAYGAIN_TRACK_GAIN=-1.45 dB
    REPLAYGAIN_ALBUM_GAIN=-1.45 dB
    artist=The Doobie Brothers
    title=Rockin' Down the Highway
    REPLAYGAIN_TRACK_GAIN=+0.03 dB
    REPLAYGAIN_ALBUM_GAIN=+0.03 dB
    artist=The Doobie Brothers
    title=Mamaloi
    REPLAYGAIN_TRACK_GAIN=+1.15 dB
    REPLAYGAIN_ALBUM_GAIN=+1.15 dB
    artist=The Doobie Brothers
    title=Toulouse Street
    REPLAYGAIN_TRACK_GAIN=+6.52 dB
    REPLAYGAIN_ALBUM_GAIN=+6.52 dB
    artist=The Doobie Brothers
    title=Cotton Mouth
    REPLAYGAIN_TRACK_GAIN=+0.16 dB
    REPLAYGAIN_ALBUM_GAIN=+0.16 dB
    artist=The Doobie Brothers
    title=Don't Start Me to Talkin'
    REPLAYGAIN_TRACK_GAIN=-1.73 dB
    REPLAYGAIN_ALBUM_GAIN=-1.73 dB
    artist=The Doobie Brothers
    title=Jesus Is Just Alright
    REPLAYGAIN_TRACK_GAIN=-0.56 dB
    REPLAYGAIN_ALBUM_GAIN=-0.56 dB
    artist=The Doobie Brothers
    title=White Sun
    REPLAYGAIN_TRACK_GAIN=+0.72 dB
    REPLAYGAIN_ALBUM_GAIN=+0.72 dB
    artist=The Doobie Brothers
    title=Disciple
    REPLAYGAIN_TRACK_GAIN=+1.03 dB
    REPLAYGAIN_ALBUM_GAIN=+1.03 dB
    artist=The Doobie Brothers
    title=Snake Man
    REPLAYGAIN_TRACK_GAIN=+2.11 dB
    REPLAYGAIN_ALBUM_GAIN=+2.11 dB

    But I can't seem to get your code to work with my script and print in the format above only tracks that are below the -4dB. Your code works really well. I can change the -4dB to -10dB and it only prints exactly what is below or above the given number, but it's not easily readable, with the directory, file names, album catalog numbers ect.ect. I am trying to get it to work with my script and output in the format above but I am failing miserably and about to give up. At the risk of asking you for too much, could I please get some more help from you on this?? Sorry Vaphell, I just can't get it to work. Thanks in advance for any more help you could be so gracious to pass my way.

    Cheers,

    Singtoh

  10. #20
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,399
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    no idea if these work, i have no flac collection so i tested this only on few sample files found on the internet

    flac_info.sh
    Code:
    #!/bin/bash
    
    shopt -s nullglob
    while (( $# ))
    do
      [ -d "$1" ] && dirs+=( "$1" )
      shift
    done
    mflac=( --no-filename --show-tag=ARTIST --show-tag=ALBUM --show-tag=TITLE --show-tag=REPLAYGAIN_ALBUM_GAIN --show-tag=REPLAYGAIN_TRACK_GAIN )
    
    
    while IFS= read -rd $'\0' dr
    do
      files=( "$dr"/*.flac )
      [ ${#files[@]} -eq 0 ] && continue
      for f in "${files[@]}"
      do
        metaflac "${mflac[@]}" "$f"
        echo "-----"
      done
    done < <( find "${dirs[@]}" -type d -print0 )
    gain.awk (should be executable)
    Code:
    #!/usr/bin/awk -f
    
            BEGIN { FS="[ =]"; ag=1000; tg=1000; }
        /ARTIST=/ { a=$0; }
         /TITLE=/ { t=$0; }
         /ALBUM=/ { al=$0; }
    /ALBUM_GAIN=/ { ag=$2; }
    /TRACK_GAIN=/ { tg=$2; }
           /----/ {
                    if( ag<x || tg<x )
                    { 
                      print a; print t; print al;
                      printf("track gain: %s, album gain: %s\n", tg, ag);
                      print "---------";
                    }
                    a=""; t=""; al=""; ag=1000; tg=1000;
    	      }
    Code:
    ./flac_info.sh /media/Storage/Music /some/other/dir > some.file
    ./gain.awk -v x=-4 some.file
    or in 1 line
    Code:
    ./flac_info.sh /media/Storage/Music | ./gain.awk -v x=-4
    i think the 1st method is better because you can dump data about the whole music collection to file once and then only work with that file without running everything again and again.
    Last edited by Vaphell; November 29th, 2012 at 05:03 AM.
    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 2 of 4 FirstFirst 1234 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
  •