Csound Csound-dev Csound-tekno Search About

[Csnd] OT sed command suggestions

Date2011-04-30 15:28
Frompeiman khosravi
Subject[Csnd] OT sed command suggestions
Hello,

I am using a csh script (see below) to replace "[space]" with actual 
spaces in file names. I am using "sed" for this and it works for strings 
that do not have the pattern consecutively (e.g. "[space][space]"). But 
when they do, sed is only replacing the matched pattern once so the 
resulting names do not have double spaces as they should. For instance 
"hello[space][space]hello.aif" returns "hello hello.aif" as opposed to 
the expected "hello  hello.aif". Funny enough it works with this: 
"hello[space]hello[space].aif".

I am just sending this here on the off-chance that someone will have a 
quick solution, otherwise I will take it to a relevant forum. Apologies 
in advance for the off topic message. Anyhow, the connection is that I 
am building a MaxMSP fronted for some csound utilities and max does not 
pass spaces in a string to the shell (a nightmare) so I am having to 
find this workaround by first replacing the spaces with a pattern and 
parsing the result in the script.

Best,

Peiman



set path =  `echo "$argv[1]" | sed s/"\[space]"/' '/g`



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-04-30 15:39
FromSteven Yi
SubjectRe: [Csnd] OT sed command suggestions
What is your sed regular expression? Are you using /g to do
find/replace of all? (I think that's the thing to do, if I remember
correctly)

On Sat, Apr 30, 2011 at 10:28 AM, peiman khosravi
 wrote:
> Hello,
>
> I am using a csh script (see below) to replace "[space]" with actual spaces
> in file names. I am using "sed" for this and it works for strings that do
> not have the pattern consecutively (e.g. "[space][space]"). But when they
> do, sed is only replacing the matched pattern once so the resulting names do
> not have double spaces as they should. For instance
> "hello[space][space]hello.aif" returns "hello hello.aif" as opposed to the
> expected "hello  hello.aif". Funny enough it works with this:
> "hello[space]hello[space].aif".
>
> I am just sending this here on the off-chance that someone will have a quick
> solution, otherwise I will take it to a relevant forum. Apologies in advance
> for the off topic message. Anyhow, the connection is that I am building a
> MaxMSP fronted for some csound utilities and max does not pass spaces in a
> string to the shell (a nightmare) so I am having to find this workaround by
> first replacing the spaces with a pattern and parsing the result in the
> script.
>
> Best,
>
> Peiman
>
>
>
> set path =  `echo "$argv[1]" | sed s/"\[space]"/' '/g`
>
>
>
> Send bugs reports to the Sourceforge bug tracker
>           https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>
>


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Date2011-04-30 15:43
Frompeiman khosravi
SubjectRe: [Csnd] OT sed command suggestions
On 30/04/2011 15:39, Steven Yi wrote:
> What is your sed regular expression? Are you using /g to do
> find/replace of all? (I think that's the thing to do, if I remember
> correctly)
Thanks Steven,

yes, this is the line from my script, which uses /g.

set path =  `echo "$argv[1]" | sed s/"\[space]"/' '/g`


Best,

Peiman


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-04-30 16:02
FromSteven Yi
SubjectRe: [Csnd] OT sed command suggestions
Hi Peiman,

I tried this on the commandline:

echo "hello[space][space]hello.aif" | sed s/"\[space]"/' '/g

and got the expected result of:

hello  hello.aif

(two spaces)

Maybe try echoing $argv[1] to make sure it came in with two [space]'s
and somehow didn't get filtered by something Max was doing?

steven

On Sat, Apr 30, 2011 at 10:43 AM, peiman khosravi
 wrote:
> On 30/04/2011 15:39, Steven Yi wrote:
>>
>> What is your sed regular expression? Are you using /g to do
>> find/replace of all? (I think that's the thing to do, if I remember
>> correctly)
>
> Thanks Steven,
>
> yes, this is the line from my script, which uses /g.
>
> set path =  `echo "$argv[1]" | sed s/"\[space]"/' '/g`
>
>
> Best,
>
> Peiman
>
>
> Send bugs reports to the Sourceforge bug tracker
>           https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>
>


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Date2011-04-30 16:32
Frompeiman khosravi
SubjectRe: [Csnd] OT sed command suggestions
Thanks very much Steven,

I am going to do some debugging straight away. Something is not right :-)

Best,

Peiman

On 30/04/2011 16:02, Steven Yi wrote:
> Hi Peiman,
>
> I tried this on the commandline:
>
> echo "hello[space][space]hello.aif" | sed s/"\[space]"/' '/g
>
> and got the expected result of:
>
> hello  hello.aif
>
> (two spaces)
>
> Maybe try echoing $argv[1] to make sure it came in with two [space]'s
> and somehow didn't get filtered by something Max was doing?
>
> steven
>
> On Sat, Apr 30, 2011 at 10:43 AM, peiman khosravi
>   wrote:
>> On 30/04/2011 15:39, Steven Yi wrote:
>>> What is your sed regular expression? Are you using /g to do
>>> find/replace of all? (I think that's the thing to do, if I remember
>>> correctly)
>> Thanks Steven,
>>
>> yes, this is the line from my script, which uses /g.
>>
>> set path =  `echo "$argv[1]" | sed s/"\[space]"/' '/g`
>>
>>
>> Best,
>>
>> Peiman
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>>
>>
>
> Send bugs reports to the Sourceforge bug tracker
>              https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-04-30 16:44
Frompeiman khosravi
SubjectRe: [Csnd] OT sed command suggestions
OK as you say it works directly in the terminal, but not when running as 
part of the script (below).


#!/bin/tcsh

set path =  `echo "untitl[space][space]ed[space]folder" | sed 
s/"\[space]"/' '/g`

echo "$path"




The result is:

bash-3.2$ ./extractBatch
untitl ed folder

(one space!)




On 30/04/2011 16:02, Steven Yi wrote:
> Hi Peiman,
>
> I tried this on the commandline:
>
> echo "hello[space][space]hello.aif" | sed s/"\[space]"/' '/g
>
> and got the expected result of:
>
> hello  hello.aif
>
> (two spaces)
>
> Maybe try echoing $argv[1] to make sure it came in with two [space]'s
> and somehow didn't get filtered by something Max was doing?
>
> steven
>
> On Sat, Apr 30, 2011 at 10:43 AM, peiman khosravi
>   wrote:
>> On 30/04/2011 15:39, Steven Yi wrote:
>>> What is your sed regular expression? Are you using /g to do
>>> find/replace of all? (I think that's the thing to do, if I remember
>>> correctly)
>> Thanks Steven,
>>
>> yes, this is the line from my script, which uses /g.
>>
>> set path =  `echo "$argv[1]" | sed s/"\[space]"/' '/g`
>>
>>
>> Best,
>>
>> Peiman
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>>
>>
>
> Send bugs reports to the Sourceforge bug tracker
>              https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-04-30 17:59
Fromjpff@cs.bath.ac.uk
SubjectRe: [Csnd] OT sed command suggestions
>From tcsh manula

 Command substitution
       Command  substitution  is  indicated by a command enclosed in ``'. 
The
       output from such a command is broken into  separate  words  at 
blanks,
       tabs  and  newlines, and null words are discarded.  The output is
vari-
       able and command substituted and put in place of the original string.

       Command substitutions inside double  quotes  (`"')  retain  blanks 
and
       tabs; only newlines force new words.  The single final newline does
not
       force a new word in any case.  It is thus possible for a  command 
sub-
       stitution  to  yield only part of a word, even if the command
outputs a
       complete line.

       By default, the shell since version 6.12 replaces all newline and 
car-
       riage  return characters in the command by spaces.  If this is
switched
       off by unsetting csubstnonl, newlines separate commands as usual.







Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-04-30 18:24
Frompeiman khosravi
SubjectRe: [Csnd] OT sed command suggestions
I knew I must have missed something. Thank you very much. That explains 
the issue, now I will look for a fix :-)

Best,

Peiman

On 30/04/2011 17:59, jpff@cs.bath.ac.uk wrote:
>  From tcsh manula
>
>   Command substitution
>         Command  substitution  is  indicated by a command enclosed in ``'.
> The
>         output from such a command is broken into  separate  words  at
> blanks,
>         tabs  and  newlines, and null words are discarded.  The output is
> vari-
>         able and command substituted and put in place of the original string.
>
>         Command substitutions inside double  quotes  (`"')  retain  blanks
> and
>         tabs; only newlines force new words.  The single final newline does
> not
>         force a new word in any case.  It is thus possible for a  command
> sub-
>         stitution  to  yield only part of a word, even if the command
> outputs a
>         complete line.
>
>         By default, the shell since version 6.12 replaces all newline and
> car-
>         riage  return characters in the command by spaces.  If this is
> switched
>         off by unsetting csubstnonl, newlines separate commands as usual.
>
>
>
>
>
>
>
> Send bugs reports to the Sourceforge bug tracker
>              https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-04-30 18:28
Frompeiman khosravi
SubjectRe: [Csnd] OT sed command suggestions
Well, according to this putting the whole thing inside double quotes 
should fix the issue, but that doesn't even work. Mhhh more fiddling!

P

On 30/04/2011 17:59, jpff@cs.bath.ac.uk wrote:
>  From tcsh manula
>
>   Command substitution
>         Command  substitution  is  indicated by a command enclosed in ``'.
> The
>         output from such a command is broken into  separate  words  at
> blanks,
>         tabs  and  newlines, and null words are discarded.  The output is
> vari-
>         able and command substituted and put in place of the original string.
>
>         Command substitutions inside double  quotes  (`"')  retain  blanks
> and
>         tabs; only newlines force new words.  The single final newline does
> not
>         force a new word in any case.  It is thus possible for a  command
> sub-
>         stitution  to  yield only part of a word, even if the command
> outputs a
>         complete line.
>
>         By default, the shell since version 6.12 replaces all newline and
> car-
>         riage  return characters in the command by spaces.  If this is
> switched
>         off by unsetting csubstnonl, newlines separate commands as usual.
>
>
>
>
>
>
>
> Send bugs reports to the Sourceforge bug tracker
>              https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-04-30 18:31
Frompeiman khosravi
SubjectRe: [Csnd] OT sed command suggestions
Awesome, thanks John! Just replaced [] with {} and put the whole thing 
in double quotes.

set path = "`echo "$argv[1]" | sed s/{space}/' '/g`"

Best,

Peiman





On 30/04/2011 17:59, jpff@cs.bath.ac.uk wrote:
>  From tcsh manula
>
>   Command substitution
>         Command  substitution  is  indicated by a command enclosed in ``'.
> The
>         output from such a command is broken into  separate  words  at
> blanks,
>         tabs  and  newlines, and null words are discarded.  The output is
> vari-
>         able and command substituted and put in place of the original string.
>
>         Command substitutions inside double  quotes  (`"')  retain  blanks
> and
>         tabs; only newlines force new words.  The single final newline does
> not
>         force a new word in any case.  It is thus possible for a  command
> sub-
>         stitution  to  yield only part of a word, even if the command
> outputs a
>         complete line.
>
>         By default, the shell since version 6.12 replaces all newline and
> car-
>         riage  return characters in the command by spaces.  If this is
> switched
>         off by unsetting csubstnonl, newlines separate commands as usual.
>
>
>
>
>
>
>
> Send bugs reports to the Sourceforge bug tracker
>              https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"