views:

181

answers:

3

My bash scripting is weak. I want to create a script that filters and add files to the svn.

So far i have this

ls | egrep -v "(\.tab\.|\.yy\.|\.o$|\.exe$|~$)"

I tried to output it using exec but couldnt figure out how. Before that I checked if svn add uses regex. I am not sure if it does and i couldnt figure out how to reverse the above without the -v (i tired "[^((\.tab\.|\.yy\.|\.o$|\.exe$|~$))]" but that didnt work as expected (it seems to only ignore .tab. files))

How do i create a script to add files to svn after applying a filter? Would this be the most simple way? -> use ls, grep, put into a bash array then use a foreach with an svn add $element ?

NOTE: This is using linux, i dont think i'll have this running on windows (i couldnt set up bison) so as long as it works on most linux distros i am happy. Ignore the fact the above uses .exe

+1  A: 

Try using find.

find <pattern> -prune .svn -exec svn add {} \;

The command following exec will be executed for each file and {} will be replaced with the filename at each iteration.

I'm not in front of my linux system so I can't get you a pattern that you need right now but if you read the man, you might get there.

antik
if you (or anyone) can tell me how to ignore my .svn folder this would be the correct answer.
acidzombie24
Haven't tested the above but to ignore the .svn folder, you'd use the -prune switch following (or perhaps before) your pattern.
antik
+1  A: 

A number of ways:

  1. Use backticks: svn add `ls | egrep stuff `

  2. Use xargs: ls | egrep stuff | xargs svn add

  3. Use find and xargs: find . -type f -name *.c -print | grep -v '\.svn' | xargs svn add

Obviously, change "stuff" and the "-name *.c" to suit your requirements...

Chris J
+1  A: 

Another solution to this is to add those file extensions and the .svn folder to your SVN ignore pattern.

Armed with a client configured as such, you could then do svn add * and get only what you want into SVN.

antik