regex - Use ack to find printing line in large project -


So I have a very large project, which basically prints this data set:

x, y, z,?,

I have to find out where this is being printed, so I can remove it.

grep for std :: cout but there are many files do anyone know how to find std :: cout and 4 commas in a row (i know that std :: cout and 4 will appear in a comma line but I'm not sure what else is). I thought that there would be some regular expressions for using it, such as std :: cout and "," but search for four of them.

Any thoughts?

ack 'cout. + (. +,) {4,} very much agree on the approach. '--cpp

Note that this is . + No . * , because . * match will be an empty string, therefore, ,, will match that you want to make sure that you have something between a comma, I - cpp Is also added, so that only C ++ files are searched.


Now, you said that you want to remove every line in the match, so here's how you can increase this solution to do this. Of course, if you have make sure that you have all the source code in version control, or at least one backup , if something is wrong, I can not tell exactly how your code looks. You have to check that the code works in your case.

If you've come to know that every row that gets ack is the one you want to remove, then you can use the pearl to remove that line. The regex you use is similar because Ack is in Perl and uses Perl Reggaex.

ack -f --cpp | Xargs perl -i -n -e'print /cout.+(.+) {4,} / '

ack -f --cpp Ack tells the ack to prepare a list of all C ++ files in the tree, and then the xargs call is repeatedly called the Pearl Command Line. Pearl's -i option says, "Edit file in place", -n tells loop on an input file from Pearl, and -e In order to execute for each line, we are asking Perl to say that whatever line has been read to it, it corresponds to that reggax. This effectively removes the mailing line from each file.

Comments