General :: Grep Changing The Delimiter?
May 13, 2010any way we can change the delimiter that uses grep?
I think, by default, grep uses as the delimiter.
any way we can change the delimiter that uses grep?
I think, by default, grep uses as the delimiter.
how to use grep with an expression that is constantly changing... basically this is what I am trying to do:
Code: watch "mpstat -P ALL | grep -e '`date +%r`'" which, should show me my CPU usage updated every couple seconds. The grep is being used to omit lines that aren't needed (all the useful lines start with the current time.) Problem is, it seems to execute the 'date +%r' command once.
I would like grep to execute the date command every time the watch command updates.
EDIT: I've found a workaround by putting the
Code: mpstat -P ALL | grep -e "`date +%r`" All in a shell file (that I called cpustat.sh), and then executing watch ./cpustat.sh
Would still like to know if there is an actual solution without having to create a seperate file (and preferably in one line). I have tried using a function to do the mpstat and grep part, but apparently watch doesn't play nice with functions
I'm trying to make a webpage that will display the bash variables I have in a file. These variables are used in a bash script that is run from on my server.The file looks like this:
SERVER=canfs01
SHARE=public
USERNAME=guest
[code]....
Can I have a custom delimiter for hash in perl?
View 4 Replies View RelatedI 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]....
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.
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 RelatedI 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 RelatedToday, 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]....
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 RelatedHow 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.
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.
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.
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.
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 RelatedWhen 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]....
I'm wondering if it's POSIX + ASCII or something else is mixed in?
View 1 Replies View RelatedI 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?
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?
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 RelatedI 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.
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]....
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
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]...
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!
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.
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
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?
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 RelatedI 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