Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: bash question

  1. #1
    Guest

    bash question

    Hey guys. How do you get a script to read in data from a text file? I would like to have a script I am writing read in a series of strings for naming ogg files during encoding from a seperate file. Is there a link to bash scripting eutopia that will explain all this (I am new to scripting, and programming in general)?

  2. #2

    Re:bash question

    I'm a pretty green bash newb myself, but I believe you can do something like the following example. This will echo each line of a file to the shell. (Basically you need to use redirection):

    Code:
    #!/bin/bash
    
    {
         while read line_of_text; do
              echo $line_of_text
         done
    } < /home/you/a_file_containing_some_stuff
    This will use each line of a text file as the current variable for that iteration of the loop. Just do whatever you need to do within the loop.

  3. #3

    Re:bash question

    I believe you could do something like this:

    Code:
    for i in `cat filename.txt`; do
      oggenc blah.wav -o $i # i'm just making up parameters for that
    done

  4. #4
    Guest

    Re:bash question

    This is what I have so far. I am trying to write a script that will encode to wav and then to ogg, and name the ogg from a file that I type in as the "title_file". Its not working. 8(
    Any ideas are appreciated.

    Code:
    #!/bin/bash
    echo "what is the name of your title file?"
    read title_file
    cdparanoia -Q
    cdparanoia -vwB
    for i in *.wav; do
    i=$(echo "$i"|sed "s/.wav$//")
            for t in 'cat "$title_file"'; do
    t=$(echo "$t"|sed "s/"$i"/"$t" /"$title_file"")
    oggenc "$i".wav -q 5 -t "$t"
    rm -f "$i".wav
    done

  5. #5
    Guest

    Re:bash question

    ok, disregard all that crap in the previous one. Here is what I have so far:
    Code:
    #!/bin/bash
    echo "what is the name of your title file?"
    read title_file
    cdparanoia -Q
    cdparanoia -vwB
    for i in *.wav; do
            for t in `cat "$title_file"`;do
            oggenc "$i" -q 5 -t "$t"
            done
    rm -f "$i".wav
    done
    Now, the problem, is that while the naming area works, (for t in etc...) It is in a loop, so it will go through however many names are in the naming file, encoding the first wav with all those different names, then going to the next wav and doing the same. Is there a way to make it do only one iteration in naming , and then going to the next wav?

  6. #6

    Re:bash question

    Another approach would be to make the title listing be the main loop and use ls to get the name of the next wav file (and take advantage of the fact that we are removing those wav files as we go). A bit like this (untested):
    Code:
    for t in `cat $title_file`
    do
        i=`ls -tr *.wav | head -1`
        oggenc "$i" -q 5 -t "$t"
        rm $i
    done
    I use "-tr" with ls to list the files in order of their creation date (oldest first) as using ls on it's own will break down when there is more than 9 tracks (ie file "track10" will be listed before file "track2&quot - well, that's the thinking anyway. "head -1" just throws everything away apart from the first file in the list.

  7. #7
    Guest

    Re:bash question

    That is an outstanding idea. Wish I had thought of it. Guess you have done some scripting before.
    Like I said earlier, this is my first attempt at it, and Have learned alot already (Im reading the bash scripting guide as we speak). I had never thought of doing it like that. That is much easier than how I was/am trying to do it. My current solution, which is still in progress, was to use arrays and reference them with a common index during encoding.
    ie:

    Oggenc ${wav_array[$index]} -q 5 -t ${song_array[$index]}

    or something to that extent. Thanks for the reply!

  8. #8
    Guest

    Re:bash question

    your a genius dude! worked first time out. You da man.

  9. #9

    Re:bash question

    Worked first time eh? I find that strangely disturbing, even in such a short snippet.
    8) Bugs 8)

  10. #10
    Guest

    Re:bash question

    I will send you a copy of it as soon as I get it all setup the way I want it.

Similar Threads

  1. bash question
    By shagnthings in forum Linux - General Topics
    Replies: 4
    Last Post: 02-13-2004, 02:44 AM
  2. bash scripting question
    By seanmclemon in forum Programming
    Replies: 7
    Last Post: 09-07-2003, 12:58 AM
  3. Bash scripting question
    By kenshi in forum Programming
    Replies: 6
    Last Post: 01-02-2003, 08:36 PM
  4. C++/bash Question
    By Schotty in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 11-06-2002, 12:03 AM
  5. Bash Script question....
    By gfunkmonk in forum Programming
    Replies: 6
    Last Post: 08-26-2002, 09:47 PM

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
  •