From: Luigi R. <sou...@fr...> - 2011-10-17 11:17:58
|
Hi List i am looking for a solution the the following task I know it is possible but i am not to good in scripting. I am on OS X - (using sox in the commandline) but scripting can be done here to. There is a folder with lot of split audio-files Applause_L.wav Applause_R.wav Atmosphere_1_L.wav Atmosphere_1_R.wav Now i would like the script to join the corresponding files, but therefore to check if the name is identical, except the "_L"/"_R" - part. And the End i would like to call the file i.e. Applause_ST.wav. I know it has to be in a for next loop and may need some regexp-stuff The actual sox-line is: sox -M input.l.wav input.r.wav output.wav thats the easy part. Anybody willing and able to help ?? Thanks Luigi |
From: Thor A. <ta...@to...> - 2011-10-17 11:43:44
|
On Mon, Oct 17, 2011 at 01:15:06PM +0200, Luigi Rensinghoff wrote: > Hi List > > > i am looking for a solution the the following task > > I know it is possible but i am not to good in scripting. > > I am on OS X - (using sox in the commandline) but scripting can be done here to. > > There is a folder with lot of split audio-files > > Applause_L.wav > Applause_R.wav > Atmosphere_1_L.wav > Atmosphere_1_R.wav > > Now i would like the script to join the corresponding files, but > therefore to check if the name is identical, except the "_L"/"_R" - > part. > > And the End i would like to call the file i.e. Applause_ST.wav. > > I know it has to be in a for next loop and may need some regexp-stuff > > The actual sox-line is: sox -M input.l.wav input.r.wav output.wav > > thats the easy part. > > Anybody willing and able to help ?? I'll take a stab. This assumes you are using bash as your shell and that the files are named correctly: 8<--------8<--------8<--------8<--------8<--------8<-------- for wav in *_L.wav; do sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" done 8<--------8<--------8<--------8<--------8<--------8<-------- -- best regards Thor Andreassen |
From: Fmiser <fm...@gm...> - 2011-10-17 15:15:16
|
> > Luigi Rensinghoff wrote: > > > > There is a folder with lot of split audio-files > > > > Applause_L.wav > > Applause_R.wav > > Atmosphere_1_L.wav > > Atmosphere_1_R.wav > > > > Now i would like the script to join the corresponding files, > > but therefore to check if the name is identical, except the > > "_L"/"_R" - part. > > The actual sox-line is: sox -M input.l.wav > > input.r.wav output.wav > Thor Andreassen wrote: > > I'll take a stab. > > This assumes you are using bash as your shell and that the > files are named correctly: > > 8<--------8<--------8<--------8<--------8<--------8<-------- > for wav in *_L.wav; do > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > done > 8<--------8<--------8<--------8<--------8<--------8<-------- Looks good to me. *smiles* If you want to see what it would do before doing anything, use "echo" in place of "sox -M". You _should_ see a list of all the files with each line containing the "L" file, the "R" file, and the (future) "ST" file names. Now, for the sake of understanding, here's a brief explanation. FOR loops need a list. The loop steps through each item in the list and assigns each item to the variable - one at a time. Here the varible is "wav". The list is created by shell globbing. That is, bash turns "*_L.wav" into a list of every file in the current directory that ends in _L.wav. The next thing in a FOR loop is the the DO command. There must be a line-return between the FOR line and the DO line. That's what the ";" is doing. The DO is the commands that should be run for each pass of the loop. "$wav" is where the variable is read. For each pass, bash will replace "$wav" with each items in the FOR list. Fancy stuff happens with "${wav%*_L.wav}_R.wav" $wav is effectively a shortcut way to write ${wav} that works in many situation. The {} mark the limits of the variable text so we can do extra stuff. Here that is the "%*". This means "only use the part of the variable string preceding the following text". In other words, ${wav%*_L.wav} strips "_L.wav" from this one reading of the varible. Then "_R.wav" is tacked onto the end, so if $wav is "Applause_L.wav", then "${wav%*_L.wav}_R.wav" is Applause_R.wav. The same trick is used to make Applause_ST.wav. A FOR loop ends with DONE. -- Philip |
From: Jeff S. <jef...@gm...> - 2011-10-17 14:59:24
|
On Mon, Oct 17, 2011 at 5:43 AM, Thor Andreassen <ta...@to...> wrote: > On Mon, Oct 17, 2011 at 01:15:06PM +0200, Luigi Rensinghoff wrote: >> Hi List >> >> >> i am looking for a solution the the following task >> >> I know it is possible but i am not to good in scripting. >> >> I am on OS X - (using sox in the commandline) but scripting can be done here to. >> >> There is a folder with lot of split audio-files >> >> Applause_L.wav >> Applause_R.wav >> Atmosphere_1_L.wav >> Atmosphere_1_R.wav >> >> Now i would like the script to join the corresponding files, but >> therefore to check if the name is identical, except the "_L"/"_R" - >> part. >> >> And the End i would like to call the file i.e. Applause_ST.wav. >> >> I know it has to be in a for next loop and may need some regexp-stuff >> >> The actual sox-line is: sox -M input.l.wav input.r.wav output.wav >> >> thats the easy part. >> >> Anybody willing and able to help ?? > > I'll take a stab. > > This assumes you are using bash as your shell and that the files are > named correctly: > > 8<--------8<--------8<--------8<--------8<--------8<-------- > for wav in *_L.wav; do > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > done I've been using bash for 10 years now and I didn't know about the ${<variable name>%<drop text>} syntax; I'll have to play with that. This may come in very handy. I always use to break it out and use sed on it. Very elegant Thank you for the example. > 8<--------8<--------8<--------8<--------8<--------8<-------- > > -- > best regards > Thor Andreassen > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2d-oct > _______________________________________________ > Sox-users mailing list > Sox...@li... > https://lists.sourceforge.net/lists/listinfo/sox-users > |
From: Thor A. <ta...@to...> - 2011-10-17 16:01:30
|
On Mon, Oct 17, 2011 at 08:59:12AM -0600, Jeff Sadowski wrote: > On Mon, Oct 17, 2011 at 5:43 AM, Thor Andreassen <ta...@to...> wrote: [...] > > 8<--------8<--------8<--------8<--------8<--------8<-------- > > for wav in *_L.wav; do > > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > > done > I've been using bash for 10 years now and I didn't know about the > ${<variable name>%<drop text>} syntax; I'll have to play with that. > This may come in very handy. I always use to break it out and use sed > on it. Very elegant Thank you for the example. You are welcome, the Bash reference manual has several other useful parameter expansions: http://www.gnu.org/s/bash/manual/bash.html#Shell-Parameter-Expansion [...] -- best regards Thor Andreassen |
From: Jeff S. <jef...@gm...> - 2011-10-17 17:56:11
|
On Mon, Oct 17, 2011 at 10:01 AM, Thor Andreassen <ta...@to...> wrote: > On Mon, Oct 17, 2011 at 08:59:12AM -0600, Jeff Sadowski wrote: >> On Mon, Oct 17, 2011 at 5:43 AM, Thor Andreassen <ta...@to...> wrote: > > [...] > >> > 8<--------8<--------8<--------8<--------8<--------8<-------- >> > for wav in *_L.wav; do >> > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" >> > done After thinking about it wouldn't spaces in names break this? one thing I would do because of spaces is as follows <===begin list=`ls -1 *L.wav` howmany=`echo -n "${list}"|wc -l | awk '{print $1}'` x=0; while [ "${x}" -lt "${howmany}" ]; do let x=$x+1 wav=`echo -n "${list}" | head -n ${x} | tail -n 1` sox -M "$wav" "${wav%*L.wav}R.wav" "${wav%*L.wav}ST.wav" done <=== end not as clean but I think this has gotten rid of some of the problems with special characters in the file names. I'd love an improvement on above I don't like the fact that it echos the entire list and filters on it that could potentially slow it down with a large list. >> I've been using bash for 10 years now and I didn't know about the >> ${<variable name>%<drop text>} syntax; I'll have to play with that. >> This may come in very handy. I always use to break it out and use sed >> on it. Very elegant Thank you for the example. > > You are welcome, the Bash reference manual has several other useful > parameter expansions: > > http://www.gnu.org/s/bash/manual/bash.html#Shell-Parameter-Expansion > > [...] > > -- > best regards > Thor Andreassen > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2d-oct > _______________________________________________ > Sox-users mailing list > Sox...@li... > https://lists.sourceforge.net/lists/listinfo/sox-users > |
From: Jan S. <ha...@st...> - 2011-10-18 12:25:44
|
On Oct 17 11:56:03, Jeff Sadowski wrote: > On Mon, Oct 17, 2011 at 10:01 AM, Thor Andreassen <ta...@to...> wrote: > > On Mon, Oct 17, 2011 at 08:59:12AM -0600, Jeff Sadowski wrote: > >> On Mon, Oct 17, 2011 at 5:43 AM, Thor Andreassen <ta...@to...> wrote: > > > > [...] > > > >> > 8<--------8<--------8<--------8<--------8<--------8<-------- > >> > for wav in *_L.wav; do > >> > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > >> > done > After thinking about it wouldn't spaces in names break this? > one thing I would do because of spaces is as follows > > <===begin > list=`ls -1 *L.wav` > howmany=`echo -n "${list}"|wc -l | awk '{print $1}'` > x=0; > while [ "${x}" -lt "${howmany}" ]; do > let x=$x+1 > wav=`echo -n "${list}" | head -n ${x} | tail -n 1` > sox -M "$wav" "${wav%*L.wav}R.wav" "${wav%*L.wav}ST.wav" > done > <=== end That's seven useless processes for each pair ov WAVs. |
From: Thor A. <ta...@to...> - 2011-10-17 22:02:02
|
On Mon, Oct 17, 2011 at 11:56:03AM -0600, Jeff Sadowski wrote: > On Mon, Oct 17, 2011 at 10:01 AM, Thor Andreassen <ta...@to...> wrote: > > On Mon, Oct 17, 2011 at 08:59:12AM -0600, Jeff Sadowski wrote: > >> On Mon, Oct 17, 2011 at 5:43 AM, Thor Andreassen <ta...@to...> wrote: > > > > [...] > > > >> > 8<--------8<--------8<--------8<--------8<--------8<-------- > >> > for wav in *_L.wav; do > >> > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > >> > done > After thinking about it wouldn't spaces in names break this? No, this works with spaces because the arguments are quoted. > one thing I would do because of spaces is as follows > > <===begin > list=`ls -1 *L.wav` > howmany=`echo -n "${list}"|wc -l | awk '{print $1}'` This part could also be accomplished thus: list=(*L.wav) # create array of files howmany=${#list[*]} > x=0; > while [ "${x}" -lt "${howmany}" ]; do > let x=$x+1 > wav=`echo -n "${list}" | head -n ${x} | tail -n 1` > sox -M "$wav" "${wav%*L.wav}R.wav" "${wav%*L.wav}ST.wav" > done > <=== end To iterate over the array do: for i in `seq 0 $(( howmany - 1 ))`; do sox -M "${list[i]}" "${list[i]%*L.wav}R.wav" "${list[i]%*L.wav}ST.wav" done Btw. instead of the ideom head -n ${x} | tail -n 1 it is usually faster to use sed, e.g. sed -n "${x}{p;q}" Where $x is the line number. [...] -- best regards Thor Andreassen |
From: Jeff S. <jef...@gm...> - 2011-10-17 22:10:41
|
On Mon, Oct 17, 2011 at 4:01 PM, Thor Andreassen <ta...@to...> wrote: > On Mon, Oct 17, 2011 at 11:56:03AM -0600, Jeff Sadowski wrote: >> On Mon, Oct 17, 2011 at 10:01 AM, Thor Andreassen <ta...@to...> wrote: >> > On Mon, Oct 17, 2011 at 08:59:12AM -0600, Jeff Sadowski wrote: >> >> On Mon, Oct 17, 2011 at 5:43 AM, Thor Andreassen <ta...@to...> wrote: >> > >> > [...] >> > >> >> > 8<--------8<--------8<--------8<--------8<--------8<-------- >> >> > for wav in *_L.wav; do >> >> > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" >> >> > done >> After thinking about it wouldn't spaces in names break this? > > No, this works with spaces because the arguments are quoted. the for part is where I think the spaces would mess it up getting it in to the way variable. doesn't the for delimit by space? > >> one thing I would do because of spaces is as follows >> >> <===begin >> list=`ls -1 *L.wav` >> howmany=`echo -n "${list}"|wc -l | awk '{print $1}'` > > This part could also be accomplished thus: > > list=(*L.wav) # create array of files > howmany=${#list[*]} > >> x=0; >> while [ "${x}" -lt "${howmany}" ]; do >> let x=$x+1 >> wav=`echo -n "${list}" | head -n ${x} | tail -n 1` >> sox -M "$wav" "${wav%*L.wav}R.wav" "${wav%*L.wav}ST.wav" >> done >> <=== end > > To iterate over the array do: > > for i in `seq 0 $(( howmany - 1 ))`; do > sox -M "${list[i]}" "${list[i]%*L.wav}R.wav" "${list[i]%*L.wav}ST.wav" > done > > Btw. instead of the ideom > > head -n ${x} | tail -n 1 > > it is usually faster to use sed, e.g. > > sed -n "${x}{p;q}" > > Where $x is the line number. > > [...] > > -- > best regards > Thor Andreassen > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2d-oct > _______________________________________________ > Sox-users mailing list > Sox...@li... > https://lists.sourceforge.net/lists/listinfo/sox-users > |
From: Thor A. <ta...@to...> - 2011-10-17 22:26:27
|
On Mon, Oct 17, 2011 at 04:10:34PM -0600, Jeff Sadowski wrote: > On Mon, Oct 17, 2011 at 4:01 PM, Thor Andreassen <ta...@to...> wrote: > > On Mon, Oct 17, 2011 at 11:56:03AM -0600, Jeff Sadowski wrote: > >> On Mon, Oct 17, 2011 at 10:01 AM, Thor Andreassen <ta...@to...> wrote: > >> > On Mon, Oct 17, 2011 at 08:59:12AM -0600, Jeff Sadowski wrote: > >> >> On Mon, Oct 17, 2011 at 5:43 AM, Thor Andreassen <ta...@to...> wrote: > >> > > >> > [...] > >> > > >> >> > 8<--------8<--------8<--------8<--------8<--------8<-------- > >> >> > for wav in *_L.wav; do > >> >> > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > >> >> > done > >> After thinking about it wouldn't spaces in names break this? > > > > No, this works with spaces because the arguments are quoted. > the for part is where I think the spaces would mess it up getting it > in to the way variable. > doesn't the for delimit by space? Ah I see what you mean, this is not a problem because the asterisk (*) is expanded after word splitting, e.g. see: http://www.gnu.org/software/bash/manual/bashref.html#Filename-Expansion [...] -- best regards Thor Andreassen |
From: Jan S. <ha...@st...> - 2011-10-18 12:24:11
|
On Oct 17 13:43:28, Thor Andreassen wrote: > On Mon, Oct 17, 2011 at 01:15:06PM +0200, Luigi Rensinghoff wrote: > > Hi List > > > > > > i am looking for a solution the the following task > > > > I know it is possible but i am not to good in scripting. > > > > I am on OS X - (using sox in the commandline) but scripting can be done here to. > > > > There is a folder with lot of split audio-files > > > > Applause_L.wav > > Applause_R.wav > > Atmosphere_1_L.wav > > Atmosphere_1_R.wav > > > > Now i would like the script to join the corresponding files, but > > therefore to check if the name is identical, except the "_L"/"_R" - > > part. > > > > And the End i would like to call the file i.e. Applause_ST.wav. > > > > I know it has to be in a for next loop and may need some regexp-stuff > > > > The actual sox-line is: sox -M input.l.wav input.r.wav output.wav > > > > thats the easy part. > > > > Anybody willing and able to help ?? > > I'll take a stab. > > This assumes you are using bash as your shell and that the files are > named correctly: > > 8<--------8<--------8<--------8<--------8<--------8<-------- > for wav in *_L.wav; do > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > done > 8<--------8<--------8<--------8<--------8<--------8<-------- Don't script in bash, script in something portable, i.e. sh(1). The UNIX world is not Linux; the OP is on MacOS, for example. bash is somewhere, sh(1) is everywhere. Alter the names as "${wav%_L.wav}_R.wav", not "${wav%*_L.wav}_R.wav". It happens to do the same thing, but you want to trim the "_L.wav", not "the shortest match of [anything]_L.wav". |
From: Thor A. <ta...@to...> - 2011-10-18 15:27:49
|
On Tue, Oct 18, 2011 at 02:24:01PM +0200, Jan Stary wrote: > On Oct 17 13:43:28, Thor Andreassen wrote: [...] > > 8<--------8<--------8<--------8<--------8<--------8<-------- > > for wav in *_L.wav; do > > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > > done > > 8<--------8<--------8<--------8<--------8<--------8<-------- [...] > Alter the names as "${wav%_L.wav}_R.wav", not "${wav%*_L.wav}_R.wav". > It happens to do the same thing, but you want to trim the "_L.wav", > not "the shortest match of [anything]_L.wav". My mistake, much better without the wildcard. Didn't realise that this is specified by POSIX. http://pubs.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_06_02 -- best regards Thor Andreassen |
From: Fmiser <fm...@gm...> - 2011-10-18 18:45:57
|
> Jan Stary wrote: > Don't script in bash, script in something portable, i.e. sh(1). > The UNIX world is not Linux; I use bash for my scripts because I use bash for my shell. Perfect fit. And nearly all the machine I manage _are_ linux. And the ones that are not are different enough that even if the script was portable other things would break. However, if you said "Don't scripts in bash if you want it to be portable", I can agree. -- Philip |
From: Jan S. <ha...@st...> - 2011-10-18 12:27:34
|
On Oct 18 00:26:19, Thor Andreassen wrote: > On Mon, Oct 17, 2011 at 04:10:34PM -0600, Jeff Sadowski wrote: > > On Mon, Oct 17, 2011 at 4:01 PM, Thor Andreassen <ta...@to...> wrote: > > > On Mon, Oct 17, 2011 at 11:56:03AM -0600, Jeff Sadowski wrote: > > >> On Mon, Oct 17, 2011 at 10:01 AM, Thor Andreassen <ta...@to...> wrote: > > >> > On Mon, Oct 17, 2011 at 08:59:12AM -0600, Jeff Sadowski wrote: > > >> >> On Mon, Oct 17, 2011 at 5:43 AM, Thor Andreassen <ta...@to...> wrote: > > >> > > > >> > [...] > > >> > > > >> >> > 8<--------8<--------8<--------8<--------8<--------8<-------- > > >> >> > for wav in *_L.wav; do > > >> >> > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav" > > >> >> > done > > >> After thinking about it wouldn't spaces in names break this? > > > > > > No, this works with spaces because the arguments are quoted. > > the for part is where I think the spaces would mess it up getting it > > in to the way variable. > > doesn't the for delimit by space? > > Ah I see what you mean, this is not a problem because the asterisk (*) > is expanded after word splitting, e.g. see: The asterisk should not be there in the first place. And the asterisk has nothing to do with spaces in the names. And the spaces in the names are not a problem, as the names are quoted. |
From: Fmiser <fm...@gm...> - 2011-10-18 18:45:58
|
> > > > Thor Andreassen wrote: > > > > > > > > for wav in *_L.wav; do > > > > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav"; done > > > Jeff Sadowski wrote: > > > > > > the for part is where I think the spaces would mess it up > > > getting it in to the way variable. > > > doesn't the for delimit by space? > > Thor Andreassen wrote: > > > > Ah I see what you mean, this is not a problem because the > > asterisk (*) is expanded after word splitting, e.g. see: > Jan Stary wrote: > > The asterisk should not be there in the first place. > And the asterisk has nothing to do with spaces in the names. > And the spaces in the names are not a problem, as the names > are quoted. Jeff was referring to the asterisk in the line . "for wav in *_L.wav; do" It is needed in that location. Right? -- Philip |
From: Jan S. <ha...@st...> - 2011-10-19 07:25:42
|
On Oct 18 13:44:26, Fmiser wrote: > > > > > Thor Andreassen wrote: > > > > > > > > > > for wav in *_L.wav; do > > > > > sox -M "$wav" "${wav%*_L.wav}_R.wav" "${wav%*_L.wav}_ST.wav"; done > > > > > Jeff Sadowski wrote: > > > > > > > > the for part is where I think the spaces would mess it up > > > > getting it in to the way variable. > > > > doesn't the for delimit by space? > > > > Thor Andreassen wrote: > > > > > > Ah I see what you mean, this is not a problem because the > > > asterisk (*) is expanded after word splitting, e.g. see: > > > Jan Stary wrote: > > > > The asterisk should not be there in the first place. > > And the asterisk has nothing to do with spaces in the names. > > And the spaces in the names are not a problem, as the names > > are quoted. > > Jeff was referring to the asterisk in the line > . "for wav in *_L.wav; do" > > It is needed in that location. > > Right? Right, sorry. |