grep a list of specific files [closed] - grep

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I need to grep for a string but only within certain files within a directory- eg:
grep -rl mystring "file1.txt file2.txt file3.blah"
what is the correct syntax? I am working in a Linux OS.

Drop the quotes around the file names so that they are treated as separate parameters. Also, I don't think you need the -r since you are just specifying files and not folders.
grep mystring file1.txt file2.txt file3.blah
You might want to check out http://ss64.com/bash/grep.html (or man grep) for other examples.

You can just give the list without quotes, it will list all results with the file they are in. eg:
grep init foo.py bar.py
foo.py: def __init__(self, label, active, filter, filter_string):
foo.py: def __init__(self):
bar.py: def __init__(self, prefs, num_panes):

Related

How to find the longest string in a column with Ruby on Rails? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What is the most efficient way in Ruby to find the longest string from a column X?
Update:
This also sort of works:
def self.length_of_longest_number
Invoice.order("LENGTH(number) DESC").first.number.length
end
Just curious to know if's efficient or not. And if it works in MySQL and Postgres...
With MySql:
# Change your model name and field to your needs
Participant.order("MAX(CHAR_LENGTH(first_name)) desc").limit(1)
# works too:
Participant.order("MAX(CHAR_LENGTH(first_name)) desc").first
# and this is the most efficient to get the field directly:
Participant.limit(1).order("MAX(CHAR_LENGTH(first_name)) desc").pluck(:first_name)
With postgres:
Participants.limit(1).order("MAX(CHAR_LENGTH(name)) desc").group("id").pluck(:name)
This also sort of works:
def self.length_of_longest_number
Invoice.order("LENGTH(number) DESC").first.number.length
end
Just curious to know if's efficient or not. And if it works in MySQL and Postgres...

Removing Double-Quotes with Ruby and Rails and .gsub [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Im using ruby and rails to automatically create a filename from the name of the product and the product's variant-type. Using .gsub, the filename will be lowercase and have special characters (spaces, ', -) removed. Ive got most of it working but I can't seem to get it to remove double quotes.
This works for single quotes:
"'"
But this doesn't work for double-quotes:
'"'
Here's my code:
filepath_name = product.name+"_"+variant_type.gsub(/ /,'').gsub("'", "").gsub("-", "").gsub('"', '').downcase+".mpg"
You could just use a regexp to remove anything but ascii characters like:
variant_type.gsub!(/[^0-9A-Za-z.\-]/, '')
and modify it to suit your needs. You can use rubular for a reference.

How to delete text in all occurences of a specific tag in Latex [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In my latex document I have use the tag \sout , to strike out some texts, in many places. Is there a one-shot way to delete the text in all the occurrences of the tag along with the tag ?
You could redefine the way \sout works by including the following in your document preamble:
\renewcommand{\sout}[1]{\unskip}
Here's an example illustrating the effect:
\documentclass{article}
\usepackage{ulem}% http://ctan.org/pkg/ulem
\begin{document}
Here is some \sout{text} stuff.
\renewcommand{\sout}[1]{\unskip}
Here is some \sout{text} stuff.
\end{document}
If you're using an editor that allows for searching with regular expressions, then you could do a find for the regular expression \\sout\{[^\}]+\} (note that this is untested) and replace with an empty string or space.

latex: xspace not suppressing space in combination with textit [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I put xspace at the end of most of my macros, e.g.
\newcommand*{\foobar}{foobar\index{foobar}\xspace}
but I just discovered that if the macro is placed inside textit, it does not work as expected, e.g.
Test 1: \foobar. Test 2: \textit{\foobar}.
produces
Test 1: foobar. Test 2: foobar .
with an extra space before the . character. Of course I could make a duplicate non-xspace macro for these case, but can I fix this more properly in some way?
I found the answer "hidden" in /usr/share/texmf/doc/latex/tools/xspace.pdf:
Sometimes \xspace may make the wrong
decision, and add a space when it is
not required. There may be different
reasons for this behavior but it can
always be handled by following the
macro with {}, as this has the effect
of suppressing the space.
So
Test 3: \textit{\foobar{}}.
produces
Test 3: foobar.

How to calculate line count for project [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am taking a software engineering class right now. Our assignment is to evaluate Mozilla's Thunderbird. Our assignment is to evaluate the size of Thunderbird. One metric that we need to use is the number of lines of code in the project. (Lines of code meaning not including comments or new lines).
Is there a standard way to find the number of lines or am I better off just cracking out a script to do this?
I think that I could do something like this:
# remove all comments
find -name *.java | \
sed "/\/*/,\*\// s/.*//g | \ # remove multiline comments
sed s/\/\///g # remove single line comments
# count not empty lines
find -name *.java | grep -c "<character>"
But I would need to do that for each file type. It seems like there should be some utility that does that already. (something mac/unix compatible would be preferable).
Use CLOC.. it is written in Perl and it supports almost every programming language, it's easily configurable and very fast.
One of my favorite tools to count SLOC is cloc, written in Perl. Without any extra configuration on your part, it will tell you the number of blank lines, the number of commented lines, and the number of source lines over an entire tree of source files. It breaks down the numbers by file extension as well.
The ohloh.net website uses a nice LOC calculator for their stats, which is freely available:
https://www.ohloh.net/p/loc-calculator

Resources