grep

Check if process is running

Hello, I am trying to check if a process is running. If it is running I want a return value of 'OK' and if not a return value of 'Not OK'. I can only use 'ps' without any other arguments attached (eg. ps -ef) if thats the correct term. The code I have is: if ps | grep file; then echo 'OK'; else echo 'NO'; fi The problem with this i...

grep replacement with extensive regular expression implementation

I have been using grepWin for general searching of files, and wingrep when I want to do replacements or what-have-you. GrepWin has an extensive implementation of regular expressions, however doesn't do replacements (as mentioned above). Wingrep does replacements, however has a severely limited range of regular expression implementation...

Match URL link from input string

How do I match the URL address in this string, I have other code that matches text and it seems to work, but when I try to use it here, it doesn't, it keeps saying there is "No such file or directory. I didn't know grep -o only worked on files? matchString='url={"urlPath":"http://www.google.com/","thisIsOtherText"' array=($(grep -o 'url...

Using grep with a complex string

Hi, I am looking in the content of several files for strings like: (2E)-3-({5,6-dihydroxy-3-methyl-2-oxo-4-[(1E)-prop-1-en-1-yl]-2,3-dihydro-1-benzofuran with grep, so I try to do: grep -n "(2E)-3-({5,6-dihydroxy-3-methyl-2-oxo-4-[(1E)-prop-1-en-1-yl]-2,3-dihydro-1-benzofuran" *.data but I get errors, probably due to the fact that ...

Extraction of data from a simple XML file

I've a XML file with the contents: <?xml version="1.0" encoding="utf-8"?> <job xmlns="http://www.sample.com/"&gt;programming&lt;/job&gt; I need a way to extract what is in the <job..> </job> tags, programmin in this case. This should be done on linux command prompt, using grep/sed/awk. ...

How to search functions with a certain number of parameters

Given the function name and the number of how many parameters the function has, how to list all the function definitions using egrep and regex? For example, the name of the function is "find" we are expected to find those functions "find" that have just three parameters, no more and no less like the following: sometype find ( type1 pa...

quick question for regex

Hi, I have a word list, but it has some words like East's I need to find the words, those only contain a-z and A-Z, from a word list. How to do that. I am using grep. What should I put after grep grep *** myfile.txt Thanks! ...

Powerful search-replace GUI app for Mac?

What's the best dedicated search-and-replace GUI tool on a Mac? "Find & Replace It!" seems decent, but they've ridiculously disabled the replace function in the demo, so I can't give it a real test before paying. Is there anything else comparable or better? ...

grep with regex for phone number

Hi, I would like to get the phone numbers from a file. I know the numbers have different forms, I can handle for a single one, but don't know how to get a uniform regex. For example xxx-xxx-xxxx (xxx)xxx-xxxx xxx xxx xxxx xxxxxxxxxx I can only handle 1, 2, and 4 together grep '[0-9]\{3\}[ -]\?[0-9]\{3\}[ -]\?[0-9]\{4\}' file Is t...

grep and sed command question

Hi there i have a truckload of files with sql commands in them, i have been asked to extract all database table names from the files How can I use grep and sed to parse the files and create a list of the unique table names in a text file ..one per line? the name names all seem to start with "db_" which is handy! what would be the best ...

How can I grep for a value from a shell variable?

I've been trying to grep an exact shell 'variable' using word boundaries, grep "\<$variable\>" file.txt but haven't managed to; I've tried everything else but haven't succeeded. Actually I'm invoking grep from a Perl script: $attrval=`/usr/bin/grep "\<$_[0]\>" $upgradetmpdir/fullConfiguration.txt` $_[0] and $upgradetmpdir/fullConf...

How to echo directories containing matching file with Bash?

I want to write a bash script which will use a list of all the directories containing specific files. I can use find to echo the path of each and every matching file. I only want to list the path to the directory containing at least one matching file. For example, given the following directory structure: dir1/ matches1 matches...

Is it possible to do a grep with keywords stored in the array?

Hello, Is it possible to do a grep with keywords stored in the array. Here is the possible code snippet... Please correct it args=("key1" "key2" "key3") cat file_name |while read line echo $line | grep -q -w ${args[c]} done At the moment, I can search for only one keyword. I would like to search for all the keywords which is stored...

how to remove leading whitespace from each line in a file?

I have a file that looks something like this: for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) for (i = 0; i < 100; i++) I want it to look like this (remove indentations): for (i = 0; i < 100; i++) f...

How can I get `find` to ignore .svn directories?

I often use the find command to search through source code, delete files, whatever. Annoyingly, because Subversion stores duplicates of each file in its .svn/text-base/ directories my simple searches end up getting lots of duplicate results. For example, I want to recursively search for uint in multiple messages.h and messages.cpp files:...

How can I write only certain lines of a file in Perl?

I am looking for a way to read an input file and print only select lines to an output file in Perl. The lines I want to print to the output file all begin with xxxx.xxxx.xxxx, where x is an alphanumeric character (the periods are periods, not wildcards). The lines do not all have the same ending, if that makes a difference. I'm thinking ...

How to search a particular type of web addresses?

See these url's: http://en.wikipedia.org/wiki/1_(number) http://en.wikipedia.org/wiki/10_(number) http://en.wikipedia.org/wiki/100_(number) http://en.wikipedia.org/wiki/10000_(number) Is there some way to search a list of all the pages of this format on the WWW? ...

Preserve colouring after piping grep to grep

There is a simlar question in Preserve ls colouring after grep’ing but it annoys me that if you pipe colored grep output into another grep that the coloring is not preserved. As an example grep --color WORD * | grep -v AVOID does not keep the color of the first output. But for me ls | grep FILE do keep the color, why the difference ? ...

Problems with Grep Command in bash script

Hi Guys, I'm having some rather unusual problems using grep in a bash script. Below is an example of the bash script code that I'm using that exhibits the behaviour: UNIQ_SCAN_INIT_POINT=1 cat "$FILE_BASENAME_LIST" | uniq -d >> $UNIQ_LIST sed '/^$/d' $UNIQ_LIST >> $UNIQ_LIST_FINAL UNIQ_LINE_COUNT=`wc -l $UNIQ_LIST_FINAL | cut -d \ -f...

Grep failing with Emacs (windows), and GnuWin32 Grep

Hi, I've downloaded and installed the GnuWin32 tools, and added the grep executables to the Emacs bin. I've also, for what its worth, added the GnuWin32 bin folder to my Path variable. Problem is though, when I try and run with suggested grep commands, I always get: Grep exited abnormally with code 53 at Wed Feb 24 17:16:12 For the ...