0

I am in the process of concatenating ogg audio files in bulk with the help of ffmpeg using a mylist.txt file

The format of the mylist.txt file is

file '/path/to/file1.wav'
file '/path/to/file2.wav'
file '/path/to/file3.wav'

My 'ls -l' output sample of WhattsAPP ogg audio files is similar to

-rw-rw-r-- 1 work work  64112 Nov 14 18:43 'WhatsApp Ptt 2019-11-11 at 10.19.18 AM.ogg'
-rw-rw-r-- 1 work work  24616 Nov 14 18:43 'WhatsApp Ptt 2019-11-11 at 10.19.50 AM.ogg'
-rw-rw-r-- 1 work work  26166 Nov 14 18:43 'WhatsApp Ptt 2019-11-11 at 10.20.18 AM.ogg'
-rw-rw-r-- 1 work work  69895 Nov 14 18:43 'WhatsApp Ptt 2019-11-11 at 10.21.05 AM.ogg'
-rw-rw-r-- 1 work work  85416 Nov 14 18:43 'WhatsApp Ptt 2019-11-11 at 10.27.09 AM.ogg'
  1. How do I get only the 'WhatsApp Ptt 2019-11-11 at 10.19.18 AM.ogg' portions of each line in the 'ls -l' output using cut, sed, awk or any other tool into a file using a single command?

  2. How do I add the keyword "file" before all file names in the file using a single command?

  3. Can process 1. & 2. be combined into a single command?

The contents of the final file need to look like:

file 'WhatsApp Ptt 2019-11-12 at 10.21.59 AM.ogg'
file 'WhatsApp Ptt 2019-11-12 at 10.29.45 AM.ogg'
file 'WhatsApp Ptt 2019-11-12 at 10.31.52 AM.ogg'
file 'WhatsApp Ptt 2019-11-12 at 9.31.38 AM.ogg'
4

2 Answers 2

3

It's simpler to use a glob instead of ls to work with a list of file names

for f in *; do
  echo file \'$f\'
done
3
  • Thank you so much @Bert :-) How do I add the single quotes for the file name in the output? Like file 'WhatsApp Ptt 2019-11-12 at 10.21.59 AM.ogg' Nov 14, 2019 at 19:00
  • 1
    @SijuGeorge You can escape the single quotes using the backlash character, I have updated my answer.
    – Bert
    Nov 14, 2019 at 19:04
  • Thank you :-) it works! Nov 15, 2019 at 5:08
3

/bin/ls -1

That leaves out all the goo :)

The problem being that ls in most distributions is aliased to something like “ls -la”. You can check that with “alias ls” and see if anything comes up

Also using an absolute path (with /bin/) will avoid using the alias.

4
  • Thank you so much @FranzBettaag :-) How do I add the word "file" before the file name in every line? Nov 14, 2019 at 19:01
  • /bin/ls -1 /your/directory | sed -e “s;^;file ;g” Nov 14, 2019 at 20:37
  • And make sure to use normal double quotes, not the artistic ones my iphone makes :) Nov 14, 2019 at 20:37
  • Thank you :-) I am on Ubuntu and it gave the error "^: command not found". But I got the solution from @Bert. Thanks again for caring to help :-) Nov 15, 2019 at 5:11

Not the answer you're looking for? Browse other questions tagged .