You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Steven Elliott <st...@gmail.com> on 2006/05/02 20:17:57 UTC

Using svn in a unix pipe

I realize that not all command line commands can be used in a unix pipe.

But it would really help me not only satisfy an itch but help in my
development process if someone here more knowledgeable in unix could give me
a hint.

What I am trying to do is take the output of ³svn st² and pipe that back
into ³svn add² or ³svn del² or...

I have so far got

svn st | egrep ³\?² | sed Œs/\?\(.*\)/ \1/¹ | svn add

So svn is outputting to egrep which is taking all the files marked ³?² and
sending that to sed to strip off the ³?² (which could be ³!² ..etc) which I
would then like to send to svn add (or delete or...).

Problem is the stdout is not making it to the add argument.

Any help would be appreciated.

Steven

Re: Using svn in a unix pipe

Posted by Nathan Kidd <na...@spicycrypto.ca>.
Steven Elliott wrote:
> What I am trying to do is take the output of “svn st” and pipe that 
> back into “svn add” or “svn del” or...
> 
> I have so far got
> 
> svn st | egrep “\?” | sed ‘s/\?\(.*\)/ \1/’ | svn add
> 
> Problem is the stdout is not making it to the add argument.

You could change that around, and use back-ticks:

svn add `svn st | egrep “\?” | sed ‘s/\?\(.*\)/ \1/’`

-Nathan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Using svn in a unix pipe

Posted by Ryan Schmidt <su...@ryandesign.com>.
On May 2, 2006, at 22:17, Steven Elliott wrote:

> svn st | egrep “\?” | sed ‘s/\?\(.*\)/ \1/’ | svn add

I do not believe "svn add" makes any use of things passed to it via  
stdin like that. Rather, it acceps parameters on its command line.  
The command "xargs" is useful for converting from the one to the other.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: Using svn in a unix pipe

Posted by Nathan Kidd <na...@spicycrypto.ca>.
Garrett Rooney wrote:
>> try this:
>> svn st | grep ^\? | awk '{ print $2 }' | tr "\n" "\000" | xargs -0 -n1 
>
> The problem is that 'print $2' in awk will only print out the second
> field, and by default it splits on whitespace, so if you've got
> filenames with spaces $2 is only the first chunk of it, so I suspect
> that tr won't help...

I find sed is simpler, and avoids whitespace issues:

svn st | sed -nr "/^\?/s/.{7}(.*)/'\1'/p" ...

-Nathan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Using svn in a unix pipe

Posted by Baz <br...@gmail.com>.
On 5/3/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> On 5/2/06, Baz <br...@gmail.com> wrote:
> > try this:
> > svn st | grep ^\? | awk '{ print $2 }' | tr "\n" "\000" | xargs -0 -n1 svn add
>
> The problem is that 'print $2' in awk will only print out the second
> field, and by default it splits on whitespace, so if you've got
> filenames with spaces $2 is only the first chunk of it, so I suspect
> that tr won't help...

Ah... doh! Ok that's solved by cut:
svn st | grep ^\? | cut -c 6- | tr "\n" "\000" | xargs -0 -n1 svn add

(Jorge previously suggested cut -c 6-500 which truncates at 500 chars)
Like Saulius though I usually resort to a single tool, but for me its
perl not sed:
svn st | perl -ne 'print if s/^\?.{5}(.*)/$1\000/' | xargs -0 -n1 svn add

Saulius' sed script fails when there's apostrophes in the filenames.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: Using svn in a unix pipe

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 5/2/06, Baz <br...@gmail.com> wrote:
> On 5/2/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> > svn st | grep ^\? | awk '{ print $2 }' | xargs svn add
> >
> > And it works just fine (assuming there aren't any spaces in your
> > filenames anyway).
> >
> > -garrett
>
> try this:
> svn st | grep ^\? | awk '{ print $2 }' | tr "\n" "\000" | xargs -0 -n1 svn add
>
> that should work if there's spaces in the filename, but one add at a
> time (I'm not sure if you absolutely *need* -n1 if you're using -0,
> but I've always stuck to the tricks I know)

The problem is that 'print $2' in awk will only print out the second
field, and by default it splits on whitespace, so if you've got
filenames with spaces $2 is only the first chunk of it, so I suspect
that tr won't help...

-garrett

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: Using svn in a unix pipe

Posted by Baz <br...@gmail.com>.
On 5/2/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> svn st | grep ^\? | awk '{ print $2 }' | xargs svn add
>
> And it works just fine (assuming there aren't any spaces in your
> filenames anyway).
>
> -garrett

try this:
svn st | grep ^\? | awk '{ print $2 }' | tr "\n" "\000" | xargs -0 -n1 svn add

that should work if there's spaces in the filename, but one add at a
time (I'm not sure if you absolutely *need* -n1 if you're using -0,
but I've always stuck to the tricks I know)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: Using svn in a unix pipe

Posted by Jorge Uriarte <jo...@omelas.net>.
Garrett Rooney wrote:
>>
>>  svn st | egrep "\?" | sed 's/\?\(.*\)/ \1/' | svn add
>>
> 
> svn st | grep ^\? | awk '{ print $2 }' | xargs svn add
> 
> And it works just fine (assuming there aren't any spaces in your
> filenames anyway).
> 

I usually use cut for this:

svn add `svn st | grep "^?" | cut c6-500`

I like this contest :-)

_
Jorge


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Using svn in a unix pipe

Posted by Gareth McCaughan <ga...@pobox.com>.
On Tuesday 02 May 2006 21:28, Garrett Rooney wrote:
> On 5/2/06, Steven Elliott <st...@gmail.com> wrote:
...
> >  What I am trying to do is take the output of "svn st" and pipe that back
> > into "svn add" or "svn del" or...
> >
> >  I have so far got
> >
> >  svn st | egrep "\?" | sed 's/\?\(.*\)/ \1/' | svn add
> >
> >  So svn is outputting to egrep which is taking all the files marked "?"
> > and sending that to sed to strip off the "?" (which could be "!" ..etc)
> > which I would then like to send to svn add (or delete or...).
> >
> >  Problem is the stdout is not making it to the add argument.
> >
> >  Any help would be appreciated.
>
> I suspect your sed command isn't working, if you drop the | svn add
> off the end you'll see that there just isn't any output at that point.
>
> Note that I do something very similar with awk all the time:
>
> svn st | grep ^\? | awk '{ print $2 }' | xargs svn add
>
> And it works just fine (assuming there aren't any spaces in your
> filenames anyway).

The "xargs" was missing in Steven's original pipeline.
But be careful, Steven (and others who may be reading),
because xargs may split your list up and invoke "svn add"
multiple times. Check "man xargs" on your system to see
whether you need to be scared; on mine it'll start splitting
once the command line gets beyond 5k bytes.

If there's any danger that you'll need more than that,
you want "svn add --targets". Unfortunately, that seems
to require a genuine filename:

    $ svn add --targets -
    svn: Reading from stdin is currently broken, so disabled

so you can't use a pipeline as such any more. Then again,
with a list that long you might be glad of a record of
just what you fed to "svn add" anyway.

-- 
g

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Using svn in a unix pipe

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 5/2/06, Steven Elliott <st...@gmail.com> wrote:
>  I realize that not all command line commands can be used in a unix pipe.
>
>  But it would really help me not only satisfy an itch but help in my
> development process if someone here more knowledgeable in unix could give me
> a hint.
>
>  What I am trying to do is take the output of "svn st" and pipe that back
> into "svn add" or "svn del" or...
>
>  I have so far got
>
>  svn st | egrep "\?" | sed 's/\?\(.*\)/ \1/' | svn add
>
>  So svn is outputting to egrep which is taking all the files marked "?" and
> sending that to sed to strip off the "?" (which could be "!" ..etc) which I
> would then like to send to svn add (or delete or...).
>
>  Problem is the stdout is not making it to the add argument.
>
>  Any help would be appreciated.

I suspect your sed command isn't working, if you drop the | svn add
off the end you'll see that there just isn't any output at that point.

Note that I do something very similar with awk all the time:

svn st | grep ^\? | awk '{ print $2 }' | xargs svn add

And it works just fine (assuming there aren't any spaces in your
filenames anyway).

-garrett

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: Using svn in a unix pipe

Posted by mike nicholaides <mi...@gmail.com>.
I think what you want is:

svn add * --force

This will add everyfile with a status of "?"

Also, correct me if I'm wrong, but you can't "svn delete" a file
that's not under version control (i.e. any file with "?" status)

I hope this helps,
Mike

On 5/2/06, Steven Elliott <st...@gmail.com> wrote:
>  I realize that not all command line commands can be used in a unix pipe.
>
>  But it would really help me not only satisfy an itch but help in my
> development process if someone here more knowledgeable in unix could give me
> a hint.
>
>  What I am trying to do is take the output of "svn st" and pipe that back
> into "svn add" or "svn del" or...
>
>  I have so far got
>
>  svn st | egrep "\?" | sed 's/\?\(.*\)/ \1/' | svn add
>
>  So svn is outputting to egrep which is taking all the files marked "?" and
> sending that to sed to strip off the "?" (which could be "!" ..etc) which I
> would then like to send to svn add (or delete or...).
>
>  Problem is the stdout is not making it to the add argument.
>
>  Any help would be appreciated.
>
>  Steven
>
>


--
http://ablegray.com

Re: Using svn in a unix pipe

Posted by Saulius Grazulis <gr...@akl.lt>.
On Tuesday 02 May 2006 23:17, Steven Elliott wrote:

Unix has 'xargs' command that can "transfer" arguments from the stdin list to 
the command line (see 'man xargs' on unix; beware that it mau be rather 
broken on some older flavours of unix, even on Linux...)

> I have so far got
>
> svn st | egrep ³\?² | sed Œs/\?\(.*\)/ \1/¹ | svn add
>
> So svn is outputting to egrep which is taking all the files marked ³?² and
> sending that to sed to strip off the ³?² (which could be ³!² ..etc) which I
> would then like to send to svn add (or delete or...).
>
> Problem is the stdout is not making it to the add argument.

Try 

svn st | egrep "^?" | sed 's/\?\(.*\)/ \1/' | xargs -t svn add

or 

svn st | egrep "^?" | sed 's/\?\(.*\)/ \1/' | xargs -t -n1 svn add

(to add files one by one)

This will probably do what you want.

I have also a script 'svn-add-unknown' which uses backticks and awk for this 
purpose. (I attach my svn scripts to this mail)

-- 
Dr. Saulius Gražulis

Visuomeninė organizacija "Atviras Kodas Lietuvai"
P.Vileišio g. 18
LT-10306 Vilnius
Lietuva (Lithuania)

tel/fax:      (+370-5)-210 40 05
mobilus:      (+370-684)-49802, (+370-614)-36366