grep

Shell Script, Search File for String

I'm writing a shell script that opens a file and needs to find a tag like ##FIND_ME##. The string I'm searching for is a constant (and there is only ever one instance of it.) Once I locate that string, I need it to start a new search for a different string from that point forward. My *nix skills are a little rusty, should try to imple...

Extracting data from a file

I have a file results.txt which is like: a.txt {some data} success!! b.txt {some data} success!! c.txt {some data} error!! I want to extract data from it. I want an output like: a.txt: success b.txt: success c.txt: error The problem is that the {some data} part can be arbitrarily long. How can this be done? ...

Pipe Java to Grep: Why not working?

I am trying to run this dreadfully simple command in Bash java -cp nasa-top-secret.jar gov.nasa.RocketToMoon | grep -v codehaus but grep is not working (it does not filter out my string). How can I filter my java output using grep? ...

How to pipe stderr, and not stdout?

I have a problem that writes information to stdout and stderr, and I need to grep through what's coming to stderr, while disregarding stdout. I can of course do it in 2 steps: command > /dev/null 2> temp.file grep 'something' temp.file but I would prefer to be able to do is without temp files. Any smart piping trick? ...

How to make git grep show at the top instead of the bottom of the terminal screen?

Suppose my terminal screen is 40 lines high. Suppose I type in "clear"; Suppose the output if git grep is only 1- lines. Now, the desired output I want is to have the first 10 lines of my console be the output of git grep. Instead, git grep fills in a bunch of blank lines and makes my output the bottom ten lines of the screen the out...

UNIX Script for a list of strings find those not in any file

I'm parsing a properties file to get a list of properties defiend. I want to check all the places these properties are used (target dir and subdirs), flagging up any that are defined in the properties file but not used anywhere in the targer dir. Thus far I have FILE=$1 TARGETROOT=$2 for LINE in `grep '[A-Z]*=' $FILE | awk -F '=' '{pr...

phpinfo showing on pages without being called

Some pages are showing the phpinfo() output (in HTML so not php -i) even though there is no call to phpinfo() in that page. The pages include a number of files, but i have grep'd the whole directory from base but cannot find any instance of phpinfo() or "phpinfo" etc. I've also looked at all "shell", "exec" and "eval" that could gener...

Best way to substract form input fields html

How would you best get all the input fields (text, radiobutton, checkbox, select etc) semi-automatically out of dodgy formatted html documents? Trying to get the TYPE,NAME,VALUE and OPTION for SELECT. I am currently using Xpath (in PHP) because everyone here says 'use that instead' but I'm getting nowhere with it. So I am open to sugge...

Can grep be used on a Perl variable?

Is it possible one way or another to, within a Perl script, effectively execute grep against a Perl variable? An equivalent Perl function would be equally acceptable, I just want to keep the solution as simple as possible. For example: #!/usr/bin/perl #!/bin/grep $var="foobar"; $newvar="system('grep -o "foo" $var'); sprintf $newvar;...

techniques in git grep and vim

Note: marked as community wiki I code in vim. I use git; and love git grep. Does anyone have a particularly nice set of techniques / scripts for using git grep in side of vim? Readers: please upvote answers involving vim + git grep; please downvote answers involving non-vim editors, and editors referring to external tools besides git...

Grepping for string containing dash

I want to grep for the string "-X" in a file but it's confusing this as a command line argument. I've tried grep "-X" grep \-X grep '-X' ...

Regular expression in BASH

Hello everyone, I was hoping someone could answer my quick question as I am going nuts! I have recently started learning regular expressions in my Java programming however am a little confused how to get certain features to work correctly directly in BASH. For example, the following code is not working as I think it should. echo 2222 |...

Grep / RegExp help

Hi everyone! I apologize if this is a really stupid question. I have data in the format: etc etc etc <span>etc etc etc</span> etc etc etc etc etc etc <span>etc etc etc</span> etc etc etc etc etc etc <span>etc etc etc</span> etc etc etc Is there a way to grep each line for a match that falls outside of the span tags on either side? ...

help with grep [[:alpha:]]* -o

file.txt contains: ##w## ##wew## using mac 10.6, bash shell, the command: cat file.txt | grep [[:alpha:]]* -o outputs nothing. I'm trying to extract the text inside the hash signs. What am i doing wrong? ...

Use a grepped file as an included source in bash

I'm on a shared webhost where I don't have permission to edit the global bash configuration file at /ect/bashrc. Unfortunately there is one line in the global file, mesg y, which puts the terminal in tty mode and makes scp and similar commands unavailable. My local ~./bashrc includes the global file as a source, like so: # Source globa...

filter log file by defining regexes

I have some HUGE log files (50Mb; ~500K lines) I need to start filtering some of the crap out of. The log files are being produced using log4j and have the basic pattern of: [log-level] date-time class etc, etc log-message I'm looking for a way that I can identify a regex start and regex end (or something similar) that will filte...

How do I extract the values from this data using bash and awk?

I grepped these, how do I extract the values? ... cavity_2mgl_wt_strip57001.out: Total cavity volume (A3) : ( 1.240E+01) cavity_2mgl_wt_strip58001.out: Total cavity volume (A3) : ( 2.408E+00) cavity_2mgl_wt_strip60001.out: Total cavity volume (A3) : ( 4.935E+00) cavity_2mgl_wt_strip61001....

How does Perl's grep function work with a regex?

Hi, How does the following grep function works (what does !/0o1Iil]/ do? ) @chars = grep !/0o1Iil]/, 0..9, "A".."Z", "a".."z"; use Data::Dumper; print Dumper @chars; to produce the following in @chars? $VAR1 = 0; $VAR2 = 1; $VAR3 = 2; $VAR4 = 3; $VAR5 = 4; $VAR6 = 5; $VAR7 = 6; $VAR8 = 7; $VAR9 = 8; $VAR10 = 9; $VAR11 = 'A'; $VAR1...

What's the easiest way to get an equivalent to GNU grep that supports negative lookbehinds?

I'm trying to grep through a bunch of files in nested subdirectories to look for regular expression matches; my regex requires negative lookbehind. Perl has negative lookbehind, but as far as I can tell GNU grep doesn't support negative lookbehinds. What's the easiest way to get an equivalent to GNU grep that supports negative lookbehi...

grep for value of keyvaue pair and format

When I do the following ps -aef|grep "asdf" I get a list of processes that are running. Each one of my process has the following text in the output: -ProcessName=XXXX I'd like to be able to format the out put so all I get is: The following processes are running: Process A Process B etc.. ...