Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Copy all svn:* properties from one file to another

The following script can be used to copy all SVN properties from one file (presumably a file that's already under SVN control) to another file (which you presumably want to put under SVN control, and which you want to check in with the same SVN properties).

#!/bin/sh

ORIG=$1 ; shift ;
[ -e "$ORIG" ] || exit ;

for PROP in `svn pl "$ORIG" | sed -n '2,$p'` ; do
        VALUE=`svn pg $PROP "$ORIG"` ;
        for FILE ; do
                [ -e "$FILE" ] && svn ps $PROP "$VALUE" "$FILE" ;
        done
done

# That's it, Folks!


If you put the above code in a shell script called...

svnprops.sh


... then you can run it as follows if you want to copy all svn:* properties FROM original.file TO blegga:

pvdb@localhost ~ $ ./svnprops.sh original.file blegga 
property 'svn:mime-type' set on 'blegga'
property 'svn:eol-style' set on 'blegga'
pvdb@localhost ~ $ _


... or as follows for multiple target files:

pvdb@localhost ~ $ ./svnprops.sh another.original.file blegga foo bar 
property 'svn:mime-type' set on 'blegga'
property 'svn:mime-type' set on 'foo'
property 'svn:mime-type' set on 'bar'
pvdb@localhost ~ $ _ 

substitution for 'ps -aux | grep [P]ROCESS'

as we know, invoking grep after ps with first letter of the PROCESS enclosed in brackets [] (like this: ps -aux | grep [P]ROCESS), excludes grep PROCESS from the output. so, instead of typing those brackets manualy every time, we may use the code below:
FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
ps -aux | grep "[$FIRST]$REST"


you may use it as separate shell-script -- like this:
#!/bin/sh
FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
ps -aux | grep -v "full/path/to/your/script" | grep "[$FIRST]$REST"


or just include it in your .bashrc or similar -- like this:
function psg
{
FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
ps -aux | grep "[$FIRST]$REST"
}
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS