Announcement

Collapse
No announcement yet.

<SOLVED> simple (?!) linux question: how to pipe directory list

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    <SOLVED> simple (?!) linux question: how to pipe directory list

    solution: http://kubuntuforums.net/forums/inde...7781#msg257781

    =====

    [on KB 10.10...]

    I have about 80% of this figured out, but am stuck at this point.

    What I want to do:
    1. list a directory containing a number of *.wav files;
    2. wrap each file name in quotes ('cause they contain spaces);
    3. pipe the output of this process to a command line program ("flake").

    The result will be the conversion of each *.wav file into its *.flac equivalent.

    THIS almost works, but stumbles, and I cannot tell why :
    Code:
    ls -x -Q ~ | flake -5
    Here's output of
    Code:
    ls -x -Q
    "01-Sonata In D minor BWV964 Adagio (JS Bach)-Colin Booth.wav" "02-Sonata In D minor BWV964 Allegro (JS Bach)-Colin Booth.wav"

    This look exactly right - and if I cut and paste this like so -
    Code:
    flake -5 {paste file name string here}
    it runs perfectly. But...when I try to pipe it, it doesn't. Flake just outputs "error parsing filenames" and quits. I don't know what to try next.

    Any help would be mightily appreciated.


    #2
    Re: simple (?!) linux question: how to pipe directory list

    I guess you can just run:
    Code:
    flake -5 *.wav
    ASROCK Z87 Pro4 - i5 4670K - R9 270x ☞ Triple Boot: KDE NEON ★ Windows 10 ★ Windows 7

    Comment


      #3
      Re: simple (?!) linux question: how to pipe directory list

      The quotation marks are used in a dos command prompt.

      The linux shell uses a backslash ahead of each space to tie the file name together, ie some\ file.wav, not "some file.wav"

      It took me ages to find this simple little thing after lots of grief with readable file names.
      Use the shell to navigate into a directory containing such folders and type ls.
      Note the result.
      Now type cd and the start of one of these folders and hit tab. It will auto complete a folder name, with the appropriate backslash in place.
      barry@EH-1:~$ cd Pictures/
      barry@EH-1:~/Pictures$ ls
      2009-08 Photos Images
      barry@EH-1:~/Pictures$ cd 2009-08\ Photos/
      You don&#39;t need a license to drive a sandwich.

      Comment


        #4
        Re: simple (?!) linux question: how to pipe directory list

        Originally posted by ubuntuku
        I guess you can just run:
        Code:
        flake -5 *.wav
        ubuntuku is correct. You don't need or want ls collecting filenames for you. You should use the shell's builtin pattern matching features to do the job.

        Bash Reference Manual, 3.5.8.1 Pattern Matching

        Are you quite certain that flake expects to receive a list of filenames from standard input? The flake manpage suggests that two file names may be passed as command line arguments, but does not mention processing file names from standard input.
        Welcome newbies!
        Verify the ISO
        Kubuntu's documentation

        Comment


          #5
          Re: simple (?!) linux question: how to pipe directory list

          Forgot to mention, I tried your commands within a directory containing the same file names, and here's what I got:

          Code:
          foo$ ls -x -Q . | flake -5
          
          Flake: FLAC audio encoder
          (c) 2006 Justin Ruggles
          
          usage: flake [options] <input.wav> <output.flac>
          type 'flake -h' for more details.
          
          foo$ ls -x -Q .
          "01-Sonata In D minor BWV964 Adagio (JS Bach)-Colin Booth.wav"
          "02-Sonata In D minor BWV964 Allegro (JS Bach)-Colin Booth.wav"
          foo$ flake -5 "01-Sonata In D minor BWV964 Adagio (JS Bach)-Colin Booth.wav"
          
          Flake: FLAC audio encoder
          (c) 2006 Justin Ruggles
          
          usage: flake [options] <input.wav> <output.flac>
          type 'flake -h' for more details.
          
          foo$
          Welcome newbies!
          Verify the ISO
          Kubuntu's documentation

          Comment


            #6
            Re: simple (?!) linux question: how to pipe directory list

            Originally posted by tomcloyd
            [on KB 10.10...]
            1. for these things I usually use 'find':
            Code:
            find . -name '*.wav' -exec flake '"'{}'"' '"'outputdir/{}'"' \;
            2. Or there can be another tool 'stat' that will quote filenames on output:
            Code:
            stat --printf '%N\n' *.wav
            3. Or use both:
            Code:
            find '*.wav' -exec stat --printf '%N\n' {} +
            4. or use awk as quotaton tool:
            Code:
            ls *.wav | awk '$0="\"" $0 "\""'
            5. I suppose the most closest to your case:
            Code:
            ls -Q *.wav | awk '$0="$0 $0.flac"' | xargs -n2 flake -5
            6. Use 'flac' instead of 'flake'
            Code:
            flac `ls -Q *.wav`
            ps. These examples are just examples only, since I do not know anything about flake or flac.

            Comment


              #7
              Re: simple (?!) linux question: how to pipe directory list

              i know this is not quite what your looking for , but you can do a simple

              ls -l > ~/file | grep pattern

              to create your file
              Mark Your Solved Issues [SOLVED]
              (top of thread: thread tools)

              Comment


                #8
                Re: simple (?!) linux question: how to pipe directory list

                Originally posted by ubuntuku
                I guess you can just run:
                Code:
                flake -5 *.wav
                Yeah. Indeed. Works great! You win todays Incandescent Intellect prize - an hermetically sealed package of forward slashes to use in any way you see fit!

                I am reminded of one of my favorite pieces of advice, which I obviously forget, else I wouldn't be writing this (in gratitude) to you: Do the simplest thing that could possible work. (DTSTTCPW)

                And YES, flake WILL accept a list of file names to process, rather than the single file name which the example-free documentation suggests. THAT I figured out myself, using the DTSTTCPW principle. But then I assumed I need to get clever, something specifically warned against by the author of that adage. What followed was not pretty.

                As for the nice variety of response this query received - thanks to you all. Each of you suggests something which points out aspects of the Linux CLI about which I need to learn more. Fascinating. One just has to love the cleverness and efficiency of this OS (usually!). A real delight.

                Comment

                Working...
                X