views:

64

answers:

2

I'm new to regular expressions and grep, but I've been trying to learn it to help me when using console tools.

I have to use cvs, and when I update some files, I don't need to see files that were't updated or with *.pyc extension for example. So, I created a script that calls:

cvs update -d | grep -v 'pyc$' | grep -v '^\?'

First question: why cvs update -d | grep -v '(pyc$|^\?)' dooesn't work, so I need to use cvs update -d | grep -v 'pyc$' | grep -v '^\?'?

Second question: files that weren't updated start with a line:

-f update: Updating FILE

I tried grep -v '^\-f' and grep -v '^-f', but no luck. What is wrong with my expression? Is it a regular expression problem or something about Linux that I'm not aware of?

Thanks!

+1  A: 

Answers only a part of your question:

You should try egrep instead of grep since | (alternation) and ( ) (grouping) are only supported by egrep.

EDIT:

The 2nd issue could occur since cvs writes some lines to stderr so you would need to redirect stderr to stdout by appending 2>&1 to you command.

stacker
Good, so it's an error from myself. Thanks!
Somebody still uses you MS-DOS
Ok, egrep works flawlessly. Any suggestions to the second problem?
Somebody still uses you MS-DOS
This is a great answer, I would upvote it more if I could. I think I need to study a little more about streams in Linux. http://en.wikipedia.org/wiki/Standard_streams Thanks stacker!
Somebody still uses you MS-DOS
+1  A: 

I have to use cvs, and when I update some files, I don't need to see files that were't updated or with *.pyc extension for example.

If this is the actual problem (actually two separate problems) you want solved, using grep on the output from CVS is the wrong solution from the start.

For the pyc thing, you should add a .cvsignore file to your project with a single line that says *.pyc, or add that line to an existing .cvsignore file. This will make CVS ignore all the pyc files completely instead of listing them as unknown.

The .cvsignore file applies to all files and subdirectories below the folder that contains .cvsignore, so if all the pyc files are within a specific subdirectory of the project you'd add the cvsignore file in that subdirectory, otherwise just add it in the root folder of the project.

As for ignoring files not updated - I think the "cvs update: Updating foo" output you refer to is rather what cvs update prints for each visited directory in the repository. To get rid of this printout, use the -q flag to CVS (this flag goes before the update command, like so: cvs -q update -d).

olsner
I liked your approach. +1. But I marked the other answer as accepted not only because it solved my problem, but I learned something more about grep as well. I'm using it in other scenarios where parameters like you provided aren't available.
Somebody still uses you MS-DOS
You seen to know a lot of cvs... would you mind trying to help me in another questions I asked here that have 0 answer about cvs? :)
Somebody still uses you MS-DOS
I teste -q, it works, but .cvsignore doesn't. I created a .cvsignore in my project root folder, with "*.pyc" and they keep showing when I run cvs update.
Somebody still uses you MS-DOS
It doesnt work when I put in my project root, but it works when in home folder. Thanks!
Somebody still uses you MS-DOS