Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I do svn status --show-updates and then I want to either

  • Q1: ignore (not to display) lines that start with ?
  • Q2: display only lines that start with * Note that there are few spaces before * occurs. That means that * is not the first character on the line.

How can I do that?

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

You can express those conditions using regular expressions and use grep to filter the results based on those.

The first one is ^?. The carat is a special character that represents the beginning of a line; so that expression matches the beginning of the line immediately followed by a ?.

The second one is ^ *\*. The * is a special character that qualifies the preceding character - it means the preceding character may appear zero or more times. Since * is a special character, the one you're looking for needs to be escaped, hence, \*. So that expression will match the beginning of a line followed by zero or more spaces, followed by an asterisk.

For your first condition, use the -v option for grep to negate the results.

So finally,

svn status --show-updates | grep -v '^?'

or

svn status --show-updates | grep '^ *\*'

Regular expressions are very powerful, so many Unix tools can use them. They are very much worth learning. There is a great tutorial at regular-expressions.info.

share|improve this answer
1  
Great answer. Thank you for nice explanation. –  Radek Feb 20 '12 at 5:09
2  
Depending on which grep, the ? may have special meaning. If so, you need to escape it \? –  Thorbjørn Ravn Andersen Feb 20 '12 at 9:07
add comment

Q1: A simple way is the following

svn st --show-updates -q

st is the abbreviation for status, and -q for quiet : that will exclude files that aren't already added in the repository.

Q2: if you didn't named your files with a *, you can also do this:

svn status --show_updates|grep -v \*
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.