Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
I'm wanting to be able to write a text file with a list of all the files that have been updated since the last svn update with each file on ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    4

    Formatting svn status output

    I'm wanting to be able to write a text file with a list of all the files that have been updated since the last svn update with each file on a separate line.
    To do this I need to format the output of this:

    root@server # svn status -u
    * 9 admin.php
    * 9 index.php
    * 9 functions/myfuncs.php
    N 9 functions/newfile.php
    Status against revision: 10
    into this

    root@server # svn status -u
    admin.php
    index.php
    functions/myfuncs.php
    functions/newfile.php
    I am really inexperienced in the voodoo of regex but I suspect thats what is needed here. Anyone care to share their wisdom with this noob? Thanks

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    You don't need a regular expression at all. Instead, you can use the cut utility.

    Basically, you tell cut what character separates your columns (in this instance, a space), and what columns you want (in this case, the third), and it will only give you those columns back.

    Check the man page for more info.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    4
    Sorry I shouldn't have used quote tags there
    Code:
    root@server # svn status -u
           *        9   admin.php
           *        9   index.php
           *        9   functions/myfuncs.php
           N        9   functions/newfile.php
    Status against revision:     10
    There is more than one space between those columns. I don't think theyre tab characters either. Would cut still work?

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Ah, right you are sir. Easy enough! We will resort to sed and regular expressions, then.

    Basically, we want to remove everything except for the last column:
    Code:
    alex@danu ~/test/bash $ cat svn_output 
           *        9   admin.php
           *        9   index.php
           *        9   functions/myfuncs.php
           N        9   functions/newfile.php
    alex@danu ~/test/bash $ sed -e 's/.\+ //' svn_output 
    admin.php
    index.php
    functions/myfuncs.php
    functions/newfile.php
    Why does this work? I have told sed to replace 1 or more of any character, followed by a space, with nothing. Most regular expressions are "greedy", which means that they try and match as much as they possibly can. Therefore, that last space comes as late as possible, and it catches on the space just before the last column, so everything up to and including that is removed.

    Make sense?
    DISTRO=Arch
    Registered Linux User #388732

  5. #5
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Or simply with awk, print field 3 if the line doesn't begin with Status:

    Code:
    awk '!/^Status/{print $3}' svn_output
    Regards

  6. #6
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Quote Originally Posted by Cabhan View Post
    Ah, right you are sir. Easy enough! We will resort to sed and regular expressions, then.

    Basically, we want to remove everything except for the last column:
    Code:
    alex@danu ~/test/bash $ cat svn_output 
           *        9   admin.php
           *        9   index.php
           *        9   functions/myfuncs.php
           N        9   functions/newfile.php
    alex@danu ~/test/bash $ sed -e 's/.\+ //' svn_output 
    admin.php
    index.php
    functions/myfuncs.php
    functions/newfile.php
    Why does this work? I have told sed to replace 1 or more of any character, followed by a space, with nothing. Most regular expressions are "greedy", which means that they try and match as much as they possibly can. Therefore, that last space comes as late as possible, and it catches on the space just before the last column, so everything up to and including that is removed.

    Make sense?
    Cabhan,

    You forgot the last line of his svn output.

    Regards

  7. #7
    Just Joined!
    Join Date
    Feb 2008
    Posts
    4
    Quote Originally Posted by Franklin52 View Post
    Cabhan,

    You forgot the last line of his svn output.

    Regards
    Indeed he did which leads to a trailing integer at the end of the file and Franklin yours didn't work perfectly either but thats my fault as again the status output was wrong :S
    Code:
           *            install.php
           *        9   admin.php
           *        9   .
    Status against revision:     11
    install.php is a new file. I thought it displayed N instead of a * and the version number but apparently not. Sorry.
    This is good stuff though I'm learning some tricks I didn't know. I appreciate it

  8. #8
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Did you solve the problem? If not post the exact svn output and the desired output.

    Regards

  9. #9
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Sorry for forgetting that last line. In any event, I think that my approach is more easily adaptable:
    Code:
    alex@danu ~/test/bash $ cat svn_output 
           *            install.php
           *        9   admin.php
           *        9   .
    Status against revision:     11
    alex@danu ~/test/bash $ sed -e '/^Status/ d; /^Status/ ! s/.* //' svn_output 
    install.php
    admin.php
    .
    My sed expression says that for any line that starts with "Status", ignore it. Otherwise, delete everything up through the last space.

    Note that my approach will _not_ work if any of the filenames have a space in them.
    DISTRO=Arch
    Registered Linux User #388732

  10. #10
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    if you look at the help of svn, using

    Code:
     svn help status
    you can see :
    The out-of-date information appears in the eighth column (with -u):
    '*' a newer revision exists on the server
    ' ' the working copy is up to date
    you could possible try to substring from nineth character onwards.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...