grep

Bash Script (Cygwin) to grep a logfile for multiple phrases and output a new file for each phrase.

Each logfile is titled based on the date it was created in the format YYYY-MM-DD.txt. I need to search each file for five different keywords and output five files prepended with the specific keyword and then the original logfile name. Example: Test-YYYY-MM-DD.txt grep -i -w 'keyword1' YYYY-MM-DD.txt > Keyword1-YYYY-MM-DD.txt If it's ...

Does grep work properly on pdf files?

Is it possible to search multiple pdf files using the 'grep' command. It doesn't seem to work, how do people search content on multiple pdf files? ...

Working with arrays passed byref

I would like for someone to explain this to me: function myFunction(array){ array = $.grep(array, function(n,i){return n > 1 }); } var mainArray = [1,2,3]; myFunction(mainArray); document.write(mainArray) // 1,2,3, but i'm expecting 2,3 but if i do something like array[3] = 4; in place of the $.grep line, i get 1,2,3,4. ...

Approximate string matching with a letter confusion matrix?

I'm trying to model a phonetic recognizer that has to isolate instances of words (strings of phones) out of a long stream of phones that doesn't have gaps between each word. The stream of phones may have been poorly recognized, with letter substitutions/insertions/deletions, so I will have to do approximate string matching. However, I ...

Copy/publish images linked from the html files to another server and update the HTML files referencing them

I am publishing content from a Drupal CMS to static HTML pages on another domain, hosted on a second server. Building the HTML files was simple (using PHP/MySQL to write the files). I have a list of images referenced in my HTML, all of which exist below the /userfiles/ directory. cat *.html | grep -oE [^\'\"]+userfiles[\/.*]*/[^\'\"] |...

How to FGREP 2 dashes '--'?

fgrep -ircl --include=*.{sql} "[--]" * doesn't seem to be doing the trick. Please help... Thanks for the responses guys. I am trying to replace the '--' with '#' and am having a tough time. I created a new question here. If you could help, that had be awesome. ...

Help with PHP data mangling as with sed/awk/grep

Ok guys.. I have a HTML i need to parse into a php script and mangle the data around abit. For best explanation I will show how I would do this in a bash script using awk, grep, egrep, and sed through a god awful set of pipes. Commented for clarity. curl -s http://myhost.net/mysite/ | \ # retr the document awk '/\/\a...

RegExp to match everything up to first blank line

Hi, I'm writing a bash script that will show me what TV programs to watch today, it will get this information from a text file. The text is in the following format: Monday: Family Guy (2nd May) Tuesday: House The Big Bang Theory (3rd May) Wednesday: The Bill NCIS NCIS LA (27th April) Thursday: South Park Friday: FlashForward Saturday:...

How to grep lines having specific format.

I have got a file with following format. 1234, 'US', 'IN',...... 324, 'US', 'IN',...... ... ... 53434, 'UK', 'XX', .... ... ... 253, 'IN', 'UP',.... 253, 'IN', 'MH',.... Here I want to extract only those lines having 'IN' as 2nd keyword. i.e. 253, 'IN', 'UP',.... 253, 'IN', 'MH',.... Can any one please tell me a command to grep it...

Ruby equivalent to "grep -C 5" to get context of lines around the match?

I've searched for this a bit but I must be using the wrong terms - does ruby have a way to grep for a string/regex and also return the surrounding 5 lines (above and below)? I know I could just call "grep -C 5 ..."or even write my own method, but it seems like something ruby would have and I'm just not using the right search terms. ...

Listing C/C++ functions (Code analysis in Unix)

Whether we're maintaining unfamiliar code or checking out the implementation details of an Apache module it can help if we can quickly traverse the code and build up an overview of what we're looking at. Grep serves most of my daily needs but there are some cases where it just wont do. Here's a common example of how it can help. To find...

Grep: Excluding a specific folder using

Say our folder structure looks like this: /app /app/data ... /app/secondary /app/secondary/data I want to recursively search /app/data but I do not want to search /app/secondary/data. From within the app folder, what would my grep command look like? ...

grep: excluding lines that begin with a blank character

I have a text file where some lines have a character at the beginning and some lines don't. I want to print the text file to screen, excluding the lines that don't have a character at the beginning. Can I do this with grep? ...

searching multiple strings in a single file

I want to find the lines in which atleast one of the strings among string1 and string2 are present in the file. grep 'string1' 'string2' file;-this is an error even though!! how could i do the above on unix command line? ...

Spider a Website and Return URLs Only

I'm not quite sure how best to define/articulate this, but I'm looking for a way to pseudo-spider a website. The key is that I don't actually want the content, but rather a simple list of URIs. I can get reasonably close to this idea with Wget using the --spider option, but when piping that output through a grep, I can't seem to find the...

I need to count the lines from matching config file entries, preferably with 'grep'.

I have a configuration file that has entries for various devices, with each entry separated by a blank line. I need to search the file for all instances of a given device type, and count the number of non-blank lines following the occurrence, stopping at the first blank. For example: Server=foo config line 1 config line 2 con...

How do I find, count, and display unique elements of an array using Perl?

I am a novice Perl programmer and would like some help. I have an array list that I am trying to split each element based on the pipe into two scalar elements. From there I would like to spike out only the lines that read ‘PJ RER Apts to Share’ as the first element. Then I want to print out the second element only once while counting e...

Optimizing grep (or using AWK) in a shell script

Hi - In my shell script, I am trying to search using terms found in a $sourcefile against the same $targetfile over and over. My $sourcefile is formatted as such: pattern1 pattern2 etc... The inefficient loop I have to search with is: for line in $(< $sourcefile);do fgrep $line $targetfile | fgrep "RID" >> $outputfile done I ...

trying to prune down a list of files

I have a list of files and I'm trying to extract all layer1_*.grd files. Is there a way of doing this in one grep expression? lof <- c("layer1_1.grd", "layer1_1.gri", "layer1_2.grd", "layer1_2.gri", "layer1_3.grd", "layer1_3.gri", "layer1_4.grd", "layer1_4.gri", "layer1_5.grd", "layer1_5.gri", "layer2_1.grd", "layer2_1.gri", "layer2_...

Linux - Want To Check For Possible Duplicate Directories (Probably RegEx Needed)

Hi, I have a directory which contains several directories as follows: /Music/ /Music/JoeBlogs-Back_In_Black-1980 /Music/JoeBlogs-Back_In_Black-(Remastered)-2003 /Music/JoeBlogs-Back_In_Black-(ReIssue)-1987 /Music/JoeBlogs-Thunder_Man-1947 I want a script to go through and tell me when there are 'possible' duplicates, in the example ...