Ubuntu :: Regex In Grep - Match With Any Character Combination
Dec 10, 2010
regex in grep? I need to match ANYTHING in the following with any character combination (something like * in findstr in C): grep "Delivery of nonspam" /var/log/mail.log | grep "to [URL]"
I have a keyboard with two faulty buttons, and I don't want to through away my keyboard just for two buttons.I have linux and windows, In DOS and Windows I somehow managed to get away with this problem by typing Alt+65 (for letter 'A') and so on.and in Linux while in GUI I take use of on screen keyboard. But problem starts with when I work in run level 3.
I have ack-grep installed on my local machine, and find it indispensable for quickly 'acking' through a codebase when debugging. However, on my cheap shared hosting, there is no ack-grep. One of the testimonials on betterthangrep.com mentions a
Rube Goldberg mess of find/grep/xargs which sounds like what I need, but coming from the opposite direction.
Both lines are new lines, so they won't be inline. Other than that, they are all constants, I want this regex match to be an if statement rather than returning match string. so if the $content variable contains some string that matches:
am trying to find a proper regex to match the two numbers in the following log entry.
Code: 15:08:16.142 INF Found 64468 15:08:16.142 ERR [Uniform test code=64469]
Basically the pattern I'm looking for will match the two different numbers spanned across two lines.Thought I need to use multi-line mode as follow but this doesn't match on [URL]...
I have a sed match that matches for certain string of a regex expression:
Code: tname=$(echo "$contents" | sed -n 'some pattern')
How do I match for multiple strings in the $contents and return them as an array? for example
Code: contents="this is a text, just to match patterns, here is another text to be matched" the sed func would be able to recognize both "text"s, but only one is outputted?
Possible to put it in an array? so ${bar[0]} gives one and ${bar[1]} gives another
At my work i have a legacy web system that tells the id of documents based on some given variables. this information can be used in another system to retrieve the needed file.
I am trying to automate this, and have managed to feed the variables and download the correct page using wget. The result is a result.php page with a lot of embedded info.
The information i am looking for is enclosed in single quotes on a line like this:
The information i want is the 1234 part.
I thought i could do like this from bash:
But I always get an empty string back... any idea what i am doing wrong?
I use the Actions feature of KDE's Klipper utility to run certain commands when I copy something into the clipboard that matches a particular regular expression. Unfortunately, I have to turn on Enable Clipboard Actions and select the command from a menu every time I copy something that I want to run the command on. I'd like to have that command run automatically instead.
You'd think this was possible, as there is an automatic checkbox in the action settings dialog box:
Unfortunately, that appears to do nothing. The documentation included with Klipper does not indicate what that checkbox is supposed to do.
Is it possible to configure Klipper to run a command automatically if the contents of the clipboard matches a regular expression? If not, is there another way to accomplish this?
I'm just starting out with bash scripting (yesterday, really). I want to add a file to each user's home directory, pretty simple really, and send it out via our Apple Remote Desktop system to our Macs. Here is my script: Code: #!/bin/bash
for i in $(ls -d /Users/*) doif [ -e $i/.tcshrc ] thenecho "$i/.tcshrc exists!"elseecho "$i/.tcshrc does not exist"
I need to use sed to edit a file that contains just one line. This should be pretty simple, but I've googled and can't seem to figure it out. I need to match everything from a certain string up until the first comma in the line. There are multiple commas in the line and my matching pattern is matching up until the last comma, not the first.
Here is what I'm trying:
As you can see it is matching up until the last comma. Seems like the .* is matching any character including the other commas. The output from this that I am hoping to achieve:
How can I get the regular expression to match from asdf: up until the first comma?
I want to traverse a directory and get a list of files that contain a set of patterns. I assumed I could use grep for this, but I having trouble getting grep to only return files that match ALL patterns. Here's what I've come up with so far:
However, this gives me a list of files that match ANY of the patterns in the searchpatterns.txt file. I want to match ALL of the patterns. I've looked through the man page, but can't find anything that allows me to change the "OR" to "AND" for multiple patterns.
I'm trying to find exact matches of some users in the /etc/passwd file using "grep -w", but it doesn't always work. For example, I have the following users:[URl].. So, let's say, I want to search for the user "stewart" (which doesn't exist)
Is there any way to add a character to the end of a line when a certain match text is matched. I have a text file where any line that contacts text XYZ a z is placed at the end.
I am trying to make a random sentence generator in perl. So far I can loop it x times to make a fixed quantity of words, but I don't want to do that. Or I can let it go on until I hit ctrl-C :/
I want to have it so that when it reaches a word with a sentence terminating punctuation mark it stops.
My attempt to do that was with:
This is doing the woooosh text until ctrl-C thing...
Now however I am not sure how I can cut off everything after the punctuation mark (when it exists).
I want to grep a a file for each '#' character that starts a line, the thing is the file is utf-8 and it starts with some some characters 'ef bb bf' is there a way to have grep to work with utf-8 files ?
I am filtering some output from gcc with grep. But if the output contains the accent character (`) I run into a problem.Then I have to press ctrl/c to get back to a prompt.
(1) Can someone tell me what is going on? I suspect that it is trying to match up the accent with another accent. But my output is from gcc and there is no control over the fact that it uses an accent and a single quote around a name. (2) Can someone tell me how to do the grep so it does not give the ">" prompt but instead locates "xcvr" in my example?
I have the following command that greps "/etc/cron.allow" and displays the following 9 lines of $file grep -A 9 "/etc/cron.allow" $file On the other hand I would like to grep a file for a certain text display the next couple of lines and stop when i hit a specified word or blank or pattern.Basically I would like my grep to end when the shell hits a blank, certain key word or pattern specified in command.
I want to match some filename in some text, but the filenames I have no control of, so "[" can "]" can appear in the filenames.so do I always have to use sed to addslashes to these variables before I have to grep them? and what other characters have I missed other than "[", "]", "."?
Code: $sql="SELECT table1.datetime, table1.user_id, table2.ip, FROM table1,table2 WHERE id='$id' AND (table1.id = table2.id AND table1.datetime = table2.datetime)";
In table2 the datetime fields are about 1 to 2 seconds off due to the source of the data, which I cannot change.
Is it possible via a query match table1.datetime & table2.datetime by HH:MM (ie. to the minute instead of to the second)?