Solved

Is there an awk or perl line I can use in a bash script to help automate the addition of files to an svn repo?

Posted on 2008-06-17
8
290 Views
Last Modified: 2013-12-16
When I use "svn status" in my directory:
It gives me a long list of files either preceeded by an M for "modified" or a question mark(?) for new files.

**Is there any way to add a line in a bash script that would extract only the filenames preceeded by the question mark?(new files)

Here is psuedo-what-I-want-to-do-o:
#!/bin/bash
cd /path/to/project
svn status >> status.log
FILES_TO_ADD= (INSERT MAGIC THAT EXTRACTS FILENAMES THAT NEED ADDING HERE!)
for file in $FILES_TO_ADD; do
svn add $file
done
svn commit -m "This is an awesome commit!"
0
Comment
Question by:tate1615
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:pzurowski
ID: 21807669
You have to escape "?" character.
FILES_TO_ADD=$(svn status | awk '^\?' {print $2}')

Open in new window

0
 
LVL 4

Expert Comment

by:albuitra
ID: 21807672
With grep is more easy
FILES_TO_ADD=`grep ^\? status.log `
0
 
LVL 3

Accepted Solution

by:
pzurowski earned 225 total points
ID: 21807702
with grep you will get a lot of "?" in $FILES_TO_ADD

of course that (my) code you can write so (i've forgotten about status.log file):
FILES_TO_ADD=$(awk '^\?' {print $2}' status.log)

Open in new window

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 4

Assisted Solution

by:albuitra
albuitra earned 225 total points
ID: 21807795
Not
this is a test in linux
/home/abuitrago> cat test
? hola
adios
? 1
?2
3 ?
/home/abuitrago> grep ^\? test
? hola
? 1
?2
/home/abuitrago>
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 50 total points
ID: 21807866
Do you realise that you can simply do:

svn add *
svn commit -m "This is an awesome commit!"

Any files already added will just be ignored.
0
 
LVL 3

Expert Comment

by:pzurowski
ID: 21807913
both will not work... i've forgotten about slashes

Try such script:
#!/bin/bash
cd /path/to/project
svn status >> status.log
awk '/^\?/ {print $2}' status.log | while read file; do
   svn add $file
done
svn commit -m "This is an awesome commit!"

Open in new window

0
 
LVL 3

Expert Comment

by:pzurowski
ID: 21807923
Tintin, i assume that tate1615 needs those files for something more than simple add and commit...
0
 

Author Closing Comment

by:tate1615
ID: 31468149
You guys rock!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Transparency shows that a company is the kind of business that it wants people to think it is.
Read about why it is more lucrative for an IT company to participate in government projects.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question