find

Find and Replace a section of a string with wildcard type search

I want to be able to read a file, and replace all instances of: M9S1800.2 with S1800 (I want to get rid of the M9 and the .2). The problem I am having is that the 4 digit number after the "S" can be different every time, as well as the number after the decimal. For example, It can be: M9S3200.1 or M9S5400.1 or M9S5400.2 Can so...

BASH: How to remove all files except those named in a manifest?

I have a manifest file which is just a list of newline separated filenames. How can I remove all files that are not named in the manifest from a folder? I've tried to build a find ./ ! -name "filename" command dynamically: command="find ./ ! -name \"MANIFEST\" " for line in `cat MANIFEST`; do command=${command}"! -name \"${line}\" ...

Is there a way to find a specific file and then change into the directory containing it in one go?

I'm looking for a way to find what I know will be a unique file, and then change into the directory containing that file. Something along the lines of: find . -name 'Subscription.java' | xargs cd Or: find . -name 'Subscription.java' -exec cd {} \; I know this won't work because it's both trying to cd supplying the entire absolute path, w...

How do I use .find for the last five days in ruby on rails?

Have a model called contact_email.date_sent I want to be able to run a report which displays all those where the date_sent range is between date.today and date.today 5 days ago. I assume I use something like @send_emails = Contact_Email.find(:conditions=> ???) But not clear what exactly is the best way. Thanks! ...

What is time complexity for find method in a set in c++?

set<int> s; s.insert(1); s.insert(2); ... s.insert(n); I wonder how much time it takes for s.find(k) where k is a number from 1..n? I assume it is log(n). Is it correct? ...

find string in DataGridView

I'm using a foreach loop to populate each row in a DataGridView with a string. I need to search the DataGridView to make sure that I don't add a string that is already there. What is the best way to do this? Here is my code so far: foreach (String file in openFileDialog.FileNames) { // to...

Bash script to find a directory, list its contents and sub-folders info

Hi I want to write a script that will: 1- locate folder "store" on a *nix filesystem 2- move into that folder 3- print list of contents with last modification date 4- calculate sub-folders size This folder's absolute path changes from server to server, but the folder name remains the same always. There is a config file that contai...

Find and Replace a section of a string with wildcard type search using RegEx (while retaining some text)

I am trying to replace some text in a string with different text while retaining some of the text and I am having trouble doing it. My code is: StreamReader reader = new StreamReader(fDialog.FileName.ToString()); string content = reader.ReadToEnd(); reader.Close(); /Replace M2 with M3 (this works fine) content = Regex.Replace(conten...

Find and Replace RegEx question

I am starting to get a grip on RegEx thanks to all the great help here on SO with my other questions. But I am still suck on this one: My code is: StreamReader reader = new StreamReader(fDialog.FileName.ToString()); string content = reader.ReadToEnd(); reader.Close(); I am reading in a text file and I want to search for thi...

jquery find h2 tags and append into div

Hi all, I'm trying to write a bit of jquery which finds all h2 tags inside a div (.content), then appends each one into another div (.intro). So far I have this: var h2 = $(".content").find("h2"); $(h2).each(function() { $(this).append(".intro"); }); But it's not working.. if someone could help me out, that'd be great :) ...

Using ed to manipulate files matched by find

Following the bash-hackers wiki's recommendation, I want to edit files using ed. In particular I want to do the following with ed instead of sed: find . -type f -exec sed -i -e 's/a/b/g' {} \; I see that ed doesn't have opt like sed's -e, so as far as I know, pipes and io redirections are the only way to work with it non-interactivel...

Find and Replace RegEx with wildcard search and addition of value

The below code is from my other questions that I have asked here on SO. Everyone has been so helpful and I almost have a grasp with regards to RegEx but I ran into another hurdle. This is what I basically need to do in a nutshell. I need to take this line that is in a text file that I load into my content variable: X17.8Y-1.Z0.1G0H...

Rails - eager load the number of associated records, but not the record themselves.

I have a page that's taking ages to render out. Half of the time (3 seconds) is spent on a .find call which has a bunch of eager-loaded associations. All i actually need is the number of associated records in each case, to display in a table: i don't need the actual records themselves. Is there a way to just eager load the count? Her...

jquery returning null - why?

I am using jquery ajax $.get which calls a php script on my server and retrieves content from another site (domain). It return's the full web page ok. I then want to extract html data from the 'center' tag using the .find() method, but I am having some issues. $("#btnGetData").click(function(){ $.get("pgiproxy.php",{ data: $("#formdat...

How can I match a null byte (0x00) in the Visual Studio binary editor with a find using a regular expression?

Open a file in the Visual Studio binary editor that contains a null byte (0x00), then use the Quick Find feature (Ctrl +F) to find null bytes. I would have thought I could use a regular expression such as \x00 to match null bytes but it doesn't work. Searching for any other hex value using this method works fine. Is this a VS bug, 'fea...

Prevent find from printing .git folders

I have a find command that I run, to find files named 'foo' in a directory. I want to skip the ".git" directory. The command below works except it prints an annoying ".git" any time it skips a .git directory: find . ( -name .git ) -prune -o -name '*foo*' How can I prevent the skipped ".git" directories from printing to stdout? ...

Can i use a model object directly in a find

I have the following models: student class teacher a student can have multiple classes, a class can have 0 or 1 teachers. I want to be able to call a method on the student to see if they have a specific teacher, and return true or false. The following code seems to work, but i thought it looked a bit long winded, having to compare eac...

Slow queries in Rails- not sure if my indexes are being used.

I'm doing a quite complicated find with lots of includes, which rails is splitting into a sequence of discrete queries rather than do a single big join. The queries are really slow - my dataset isn't massive, with none of the tables having more than a few thousand records. I have indexed all of the fields which are examined in the que...

Find and replace question regarding RegEx.Replace

Hello, I have a text file and I want to be able to change all instances of: T1M6 to N1T1M6 The T will always be a different value depending on the text file loaded. So example it could sometimes be T2M6 and that would need to be turned into N2T2M6. The N(value) must match the T(value). The M6 will always be M6. Another example:...

Rails: combining multiple find requests

What I want to do is something like this: searchid = 4 while searchid != -1 @a += A.find(searchid) @b = B.find(searchid) searchid = @b.parentid end The problem being the line @a += A.find(searchid) The error being something like NoMethodError: undefined method `+' for #<A:0x173f9a0> So, how do you combine multiple 'find...