find line in text file, add to another text file
// skips the ---------- foo.csv returned by find alone
1 2 find /i "%1" foo.csv | find /i "%1" >> bar.txt
12979 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 find /i "%1" foo.csv | find /i "%1" >> bar.txt
1 2 function my_handler($filename) { 3 echo $filename . "\n"; 4 } 5 find_files('c:/', '/php$/', 'my_handler');
1 2 function find_files($path, $pattern, $callback) { 3 $path = rtrim(str_replace("\\", "/", $path), '/') . '/'; 4 $matches = Array(); 5 $entries = Array(); 6 $dir = dir($path); 7 while (false !== ($entry = $dir->read())) { 8 $entries[] = $entry; 9 } 10 $dir->close(); 11 foreach ($entries as $entry) { 12 $fullname = $path . $entry; 13 if ($entry != '.' && $entry != '..' && is_dir($fullname)) { 14 find_files($fullname, $pattern, $callback); 15 } else if (is_file($fullname) && preg_match($pattern, $entry)) { 16 call_user_func($callback, $fullname); 17 } 18 } 19 }
1 2 #!/bin/bash 3 4 find . ! -name "*.ogg" -exec rm -f {} \;
1 2 class User < ActiveRecord::Base 3 def self.names 4 # find all records, then map name attributes to an array 5 find(:all, :select => "name").map(&:name) 6 end 7 end 8 9 # btw.. 10 .map(&:name) 11 12 # is shorthand for 13 .map { |x| x.name }
1 2 // Examples 3 var test=[1,58,'blue','baby','boy','cat',35,'35',18,18,104] 4 result1=test.find(35); //returns 6 5 result2=test.find(/^b/i); //returns 2,3,4 6 result3=test.find('35'); //returns 7 7 result4=test.find(18); // returns 8,9 8 result5=test.find('zebra'); //returns false
1 2 Array.prototype.find = function(searchStr) { 3 var returnArray = false; 4 for (i=0; i<this.length; i++) { 5 if (typeof(searchStr) == 'function') { 6 if (searchStr.test(this[i])) { 7 if (!returnArray) { returnArray = [] } 8 returnArray.push(i); 9 } 10 } else { 11 if (this[i]===searchStr) { 12 if (!returnArray) { returnArray = [] } 13 returnArray.push(i); 14 } 15 } 16 } 17 return returnArray; 18 }
1 2 grep -R --files-with-matches 'SEARCH_STRING' . | sort | uniq | xargs perl -pi~ -e 's/SEARCH_STRING/REPLACE_STRING/'
1 2 :%s/^[\ \t]*\n//g
find -name "*" -exec rm {} \; find -name "*" -exec rm {} \;; lsfind -type f -print
find . -type f -exec grep foo {} \;find dirname
find . | grep test.txt
1 2 du -hd 1 | sort -k 2
1 2 du -hd 1 | grep [0-9]K | sort -n -k 1 ; du -hd 1 | grep [0-9]M | sort -n -k 1
1 2 du -ah | grep '[0-9]K' | sort -n -k 1 | less
1 2 du -ah | grep '[0-9]M' | sort -n -k 1 | less
1 2 du -h | grep '[0-9]M' | sort -n -k 1 | less
1 2 find . -type f -size +2048 -exec du -hs {} \; | sort -n -k 1 | less
1 2 find . -name *~ -print
1 2 find . -name "*~" -exec rm {} \;