General :: How To Use Grep
Apr 7, 2011
I need to find file from ls - l by using grep and certain regexp.
In particular I need greep to see certain file ending, like let's say .txt but only using regex.
So it should be something like
ls -l | grep '^.+.txt$'
But that doesn't seem to work for me.
View 1 Replies
ADVERTISEMENT
Nov 22, 2010
I need to kind of grep within grep. My input file would be something like:
[Code]....
and I need to find the first occurrence of hello before MY PATTERN (hello 9008 in this case), so the output should be:
[Code]....
View 4 Replies
View Related
Dec 21, 2010
I need to grep a dictionary file.Only the words that contain 2 or more z's and only 1 b needs to be listed.
View 1 Replies
View Related
Jul 15, 2010
I am trying to grep for A records in a bind zone file but I am failing.I am trying: grep "s+As+" db.domain.comBut there are no results.
View 12 Replies
View Related
Jul 29, 2010
Today, i checking my error log of Apache. I have look many IP brute scan URLo, i collect, export that to ip.txt and i need grep IP with connection >=8I don't know command to solve that. Example ip.txtQuote:
101 210.13.73.30
161 58.210.77.98
164 115.168.71.87
[code]....
View 2 Replies
View Related
Feb 3, 2010
I have a file which contains a line like this:SERVER=10.205.110.19 How can I cut out the IP and assign it to a variable?
View 4 Replies
View Related
Mar 28, 2010
How can I use grep expressions so that i can find strings like the ones bellow:
New York, NY
Virginia, VA
Oregon, OR
As you can see each city starts with capital letter then it follows up with a comma, and then with the Abbreviation of the city. I used :
Code: grep -w '[A-Z].*[a-z][,][' '][A-Z][A-Z]' filename But i get no results.
View 2 Replies
View Related
Feb 19, 2011
I have on my desktop around five java files. I also created a java file in directory Viti, located in desktop.
Since all java files contain string "class", I practice my usage of grep with the following:
And this works fine. However, when I type the following:
I expect to be shown the file that's located in my Viti directory, too, but it won't show it.
View 4 Replies
View Related
Jul 3, 2010
I searched and I found a few threads on this but none answered my question really.I'm using:
Code:
curl www.foo.com | grep '<h2>.*.</h2>'
Basically I want to extract all instances of
Code:
<h2>Blah blah blah</h2>
from the page source, but it's not giving me that, it gives me <h2>.. followed by a loads of other stuff that I don't want. I haven't used wildcards with grep before so I don't really know whether I'm doing it right or not.
View 5 Replies
View Related
Dec 7, 2010
Let me *try* and explain what I'm trying to do, and keep in mind aside from a little command line stuff I'm a beginner to any of what I'm asking about.
I have a directory structure something like this:
Code:
/usr/local/chatlogs/
webserver1/
1.chatlog
2.chatlog
[Code]....
So that whatever was captured in the () in the first part of the statement would be used in the 1 in the back part of the statement for every n.chatlog that might be in any of the /webserver directories at that time.
View 2 Replies
View Related
May 13, 2010
any way we can change the delimiter that uses grep?
I think, by default, grep uses as the delimiter.
View 3 Replies
View Related
May 17, 2010
I forgot a lot of my command line. I am doing cat file | grep "error" and i would like it to show everything to the right of G:/ including G:/ if possible. I figure its an awk command but i dont know what. I tried awk '{print $8+}' but + does not work like i hoped and guessed.
View 2 Replies
View Related
Feb 22, 2011
When using the grep plugin to VIM, I can search the current directory for all occurrences of a string within a set of files, like this::grep Ryan *.txtThis outputs something like this:
file1.txt:3:Ryan was here
file2.txt:10:Ryan likes VIM
file3.txt:5:superuser.com is a fav of Ryan
[code]....
View 1 Replies
View Related
Apr 12, 2011
I'm wondering if it's POSIX + ASCII or something else is mixed in?
View 1 Replies
View Related
Mar 23, 2011
I have a server hosting 100+ websites. I need to quickly identify which websites are configured with a database. There are way too many to manually check every website for a PHP file with a database name. So, I created a list of all databases from MySQL and put them in a text file. I then exported the text file to a shell variable and used it in a for loop.
bash variable
Code:
DBLIST=`cat dblist.txt`
Example of $DBLIST
Code:
db1 db_testing2 database_clientname production words4cheap
for loop
Code:
for db in $DBLIST; do find . -type "f" -iname "*.php" -exec grep -i $db '{}' ; -print; done
Note: my find statement starts searching at . which is the directory that contains all of my websites and their data, each website is setup in a sub directory, identified by it's domain name.
Example: I'm in /var/www. Beneath /var/www are a list of directories:
[URL]
However, this is taking too long (it's been running most of the day) and I was wondering if there wasn't an easier way to accomplish what I'm trying to achieve?
View 4 Replies
View Related
Mar 9, 2011
I have a file like this:
Code:
I need to search it backwards for "notable line" strings AND the first numeric string preceding that line. I've discovered that it's easy to search backwards by tac file | grep pattern, but how to tell grep to continue searching from where the pattern was found? In short, I want to make the output of the example above into this:
Code:
Or I must use another tool, like awk or sed? If so, how do I do so?
View 3 Replies
View Related
Oct 15, 2010
I tried to run one grep that excludes symlinks and pipe it into a second that searches for my pattern but I continue to get the recursive directory loop error. As a result (I think) my grep is incomplete as the search just loops between directories symlinked together.
View 7 Replies
View Related
Dec 31, 2010
I have collection my routers configuration through rancid. Now i want to do the following,
Display all the files that contain the following words
C1841 AND HWIC-4ESW
I want to display all the files that contains both these words.
View 14 Replies
View Related
Feb 22, 2010
I am attempting to recover a deleted text file. I used dd to make an image of the sectors on the hard drive which contained the data. Now, since I am not getting good results with foremost, and know all of the lines I'm looking for contain "Style", I want to grep the .img, but when I do it runs out of memory. I have tried the grep option -D, set to skip, and tried adding a 3GB swap to account for the 2.7G image. It still "exhausts" it's memory, and it seems to happen really quick now.this is the output of ulimit -a
Code:
root: $ ulimit -a
core file size (blocks, -c) 0
[code]....
View 12 Replies
View Related
Sep 22, 2010
Is there any way i can pass two / three values to grep. Basically i want to list the lines in the file with three different values. Currently I'm using three grep to get my work done.
EG: more Filename | grep text1 | grep text2 | grep text3
BRs
View 2 Replies
View Related
Apr 16, 2010
I'm writing a program that works with text files, and I'm trying to create some filters with grep. I have various questions here, so I'll number them for clarity.
1) First of all, I'd like to know what wc -w is actually returning. The word count is less than what gedit is counting in Document Statistics, so obviously gedit is counting something (like newlines) that wc -w is not
2) Secondly, I was wondering if there was a way to grep x number of words. I'm looking for something like the -m option, but returning a certain number of words instead of lines. For example, to find the first 2000 words, do something like grep -someoption 2000 ".*" or using {1,2000}.
3) Finally, I'm trying to filter out headers and footers of a text file but having no luck. The text files are Project Gutenberg files, so they have standardized headers and footers. Here's an example: [URL]...
The header starts with "The Project Gutenberg EBook of" and ends with the line containing "START OF THIS PROJECT GUTENBERG EBOOK" The footers begin with: "End of the Project Gutenberg EBook of" My problem is, grep can find:
[Code]...
View 15 Replies
View Related
Apr 8, 2011
What does this command mean? grep 'GET / HTTP.*Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1' last10m |cut -d ' ' -f1 |sort -n |uniq -c|sort -n|tail
Whats the best way to figure out these commands in general? I have a lot of learning to do!
View 9 Replies
View Related
Mar 30, 2010
I am trying to get a word from a line using sed. Following is the line which I want to use.
inet addr:10.245.86.15 Bcast:10.245.87.255 Mask:255.255.254.0 inet6 addr: fe80::1031:3dff:fe01:55e1/64 Scope:Link
From the above line, I need the ip address like 10.245.86.15 only.
View 4 Replies
View Related
Sep 9, 2010
I want to grep any line with "john" or "jack". How to do that? I tried
grep john | grep jack
but it didn't work
View 2 Replies
View Related
Mar 6, 2011
Following is my ifconfig output code...
I want to do some thing grep that I see the IP corresponding to each LAN card?
Is that possible?
View 8 Replies
View Related
Jan 21, 2010
On my server, logs are saved in log.gz format. I want to know what regular expression should i use to search both oracle and a particular IP, say 1.2.3.4 in a single log line ?
View 6 Replies
View Related
Feb 24, 2011
I want to extract some information from ifconfig,
E.g.:
inet addr:123.123.123.123 Bcast:123.123.123.255 Mask:255.255.254.0
I want to extract the mask value, how can I do that? I've tried using
Code:
grep -o "Mask:*" test1.txt
but it only outputs "Mask:" I need to get 255.255.254.0
View 3 Replies
View Related
Jun 24, 2011
What I am usinggrep -B 1 -A 2 "Installed" /var/log/updates.logInstead of tailing the log is there a way to grep all lines of the log with word Installed AND today's date? Also, what about grep lines of the log that contain a specific date and more than one word, by example : ('Installed' or 'Failed' on '2011-06-24')?
View 14 Replies
View Related
Apr 28, 2011
Q: Is there any way to use grep and sed with a string variable rather than with a file?
The problem: Im running through a LARGE (about 10,000 lines) xhtml file and need to replace every instance of lines beginning <p>~
The following code works but takes a long time mainlly because an in/out operation needs to be carried out on each line. If I could read from a string rather than a file it would take a much shorter time!
Code:
#!/bin/bash
count=$((0))
>tpf
echo "waiting....."
[Code].....
View 4 Replies
View Related
Feb 15, 2011
I have a requirement to find the files having its name as ack_reply. However, there are many other files in the same directory as these resides. Now I have to remove these files from the folder and retain others after 7 days. So I tried to write the below script with grep command.
find $directory -type f -mtime +7 | grep ack_reply
how can I pass this output to -exec command.
If I am not using grep command my script would be as
find $directory -type f -mtime +7 -exec remove.sh {}\;;
How can I use -exec with grep and find.
View 4 Replies
View Related