开发者

Help with regular expression and grep in Linux terminal

开发者 https://www.devze.com 2023-01-07 15:38 出处:网络
I\'m new to regular expressions and grep, but I\'ve been trying to learn it to help me when using console tools.

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 开发者_如何学Go'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!


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号