Regular expressions are a means of matching a pattern of characters within a string.
2
votes
1answer
786 views
How to block the Google Analytics Script using Privoxy
Related subject: Privoxy: blocking twitter, facebook and google outside of their domains + HTTPS
Never mind what rule I am adding to the default.filter file, I don't make it to block these scripts.
...
2
votes
4answers
1k views
Extract IP address from a string
The Linux host command returns:
hostA.domain.com has address xx.xxx.xxx.xx
How do I get just the IP address and put it in the $ipaddr variable?
open(FILE, "hostlist.txt") or die("Unable to open ...
0
votes
2answers
2k views
Using grep to match only a match group in a regular expression?
I need to set my keyboard layout with setxkbmap before launching Wine games, as I use Dvorak for typing and this breaks every game's controls. What I'd like to do is simply write a script that grabs ...
1
vote
1answer
669 views
Match one part of a regular expression in a Kwrite find-and-replace regex
Among the joys of KDE, Kwrite is surely noteworthy. Having regular expression support built in by default into text editor is probably one of the top 10 best ideas of all time. Since I often need to ...
11
votes
4answers
463 views
How do I choose specific files in a different directory using bash?
I want to list (or delete, or do some other operation) on certain files in a directory, like this:
$ ls /opt/somedir/
aa bb cc aa.txt bb.txt cc.txt
$ ls /opt/somedir/(aa|bb|cc) ## pseudo-bash ...
2
votes
1answer
171 views
Expand regex on multiple lines in Vim
I am working on removing comments from a C source file. Let's focus on multiline comments
/* ... */ and ignore the inline ones (//)
The following command seems to work with (solaris) sed:
...
8
votes
5answers
1k views
Software for visually building regular expressions?
I frequently need to create regular expressions for use in scripts (mostly when used in sed), however, I find, sometimes the regular expressions get very complicated and difficult for me to understand ...
1
vote
2answers
204 views
How can I match this text in awk, printing line numbers for matches?
I have a text file thousands (roughly 148,000 lines long) that consists of a lot of sequences like this:
b 29.
b 52.
c 84.
c 83.
c 94.
c 93.
c 61.
b 38.
c 81.
c 92.
c 28.
c 37.
c 27.
... and since ...
7
votes
4answers
4k views
How can I use sed to replace a multi-line string?
I've noticed that, if I add \n to a patter for a substitute using sed, it does not match. Example:
$ cat > alpha.txt
This is
a test
Please do not
be alarmed
$ sed -i'.original' 's/a test\nPlease ...
1
vote
2answers
507 views
How to treat a file as a single line with grep to apply a regexp search pattern?
I want to match everything that is between some lines with regexp but not this that match the start and the end. This sound to me as positive lookbehind and positive lookahead
start text
bla ...
2
votes
3answers
591 views
How to cut the output to only gather the filename and get-parameter?
I have multiple files with multiple links that are formatted like this:
<a href="http://example.com/fnord.layername.html?parameter=FOO-_-BAR-_-FNORD" class="poit">
<img ... />
...
8
votes
6answers
780 views
Delete lines beginning with #
How do I delete lines beginning with a #, given that there can be whitespace on the left and right of the #?
# Master socket provides access to userdb information. It's typically
1
vote
1answer
431 views
reference problem in using sed
I'm trying to use sed command to find/replace a pattern in file.
It gives:
sed: -e expression #1, char 27: invalid reference \1 on `s' command's RHS
My command is:
sed ...
4
votes
1answer
535 views
How can I match the page break character in a regular expression?
Nano calls it ^L, but of course, typing something like
$ grep -v "^\^L" file
doesn't work. Its unicode codepoint is 000C. How can I match it in a regular expression?
4
votes
2answers
1k views
How to search and replace multiple needles by one word via one expression?
Assume you have a text file:
foo fnord bar
bizz foo poit
And now I would want to replace both "foo" and "bar" into "narf".
I know I could use:
sed -e 's/foo/narf/g' -e 's/bar/narf/g' fileName
...
3
votes
0answers
131 views
How to use regrex with AWK for string replacement in this example? [duplicate]
Possible Duplicate:
How to use regrex with AWK for string replacement in this example?
Suppose there is some text from a file:
(bookmarks
("Chapter 1 Introduction 1" "#1"
("1.1 Problem ...
5
votes
3answers
13k views
How to use regex with AWK for string replacement?
Suppose there is some text from a file:
(bookmarks
("Chapter 1 Introduction 1" "#1"
("1.1 Problem Statement and Basic Definitions 23" "#2")
("Exercises 31" "#30")
("Notes and References 42" "#34"))
)
...
1
vote
2answers
287 views
pattern search and display the last occuring pattern?
I have a log file containing startup and shutdown times for everday.
I want to see the last pattern pattern for startup and shutdown(which is located at the end of the file being updated everyday).
...
1
vote
4answers
1k views
Replacing XML entity values with positive lookaround
I'm trying to do some pretty simple sedding of a file:
sed 's:(?<=<Type>)default(?=</Type>):super:' < myfile.xml
The concept's pretty simple, using positive lookaround, find the ...
4
votes
2answers
2k views
Using regular expressions with cp
This is a simple question. I'm trying to copy all of the files in the current directory that start with "axis-2" and end with ".jar" into a target directory, let's say it's ~/MyDirectory. My first ...
5
votes
3answers
560 views
Regex & Sed/Perl: Match word that ISN'T preceded by another word
I'd like to use sed or perl to replace all occurrences of a word that doesn't have a certain word in front of it.
For example, I have a text file that contains a plot of a movie and I want to replace ...
4
votes
2answers
311 views
grep caret appears to have no effect
I was under the impression that a caret symbol means "beginning of the line" with Extended POSIX regular expressions.
However, when I use it with grep it behaves unexpectedly.
#grep --version
GNU ...
4
votes
3answers
164 views
vim regex not need \ to escape
In Vim is there an option to write regexs in the same style as Awk for example/sp\{0,\}/ Would be
/sp{0,}/
3
votes
2answers
599 views
simple command to strip header and footer from a file
I want a simple little command to strip an XML-Header and Footer from a file:
<?xml version="1.0" encoding="UTF-8"?>
<conxml>
<MsgPain001>
...
3
votes
2answers
525 views
Wget - Mirroring a full website with requisites on differents hosts
I am trying to make a full static copy of a wordpress website with wget to be browsed without any network connection (all links and images must be converted).
The different requisites for the pages ...
3
votes
4answers
3k views
Match regex in ksh
I am looking to do something like this in KSH:
if (( $var = (foo|bar)[0-9]*$ )); then
print "variable matched regex"
fi
Is it possible at all?
For the record I'm using Ksh Version M-11/16/88i ...
0
votes
1answer
205 views
What does ^> mean in a grep pattern?
What does this command do?
grep "<[^>]*>" inuux.xml
What is searching for?
4
votes
1answer
670 views
What does \bi\b mean in a grep pattern?
What does this command do?
grep "\bi\b" linux.txt
What is it searching for?
3
votes
2answers
345 views
Replace a substring of filenames in a directory
There exists a directory, which includes several levels of sub-directories. Under these directories, there are a set of files whose names include a common word, e.g, .cc. How can I replace the .cc ...
5
votes
2answers
955 views
How to use regex as field separator in awk?
I'm trying to use regex as a field seperator in awk. From my reading this seems possible but I can't get the syntax right.
rpm -qa | awk '{ 'FS == [0-9]' ; print $1 }'
awk: cmd. line:1: { FS
awk: ...
-1
votes
1answer
267 views
How to “grep -v” private/broadcast IPv4 addresses?
time nmap -n -iR 0 -sL | cut -d " " -f 5 | egrep -v "^10.*|^172.[16\-32].*|^192.168.*|^[224\-255].*" > RANDOM-IPS.txt
so the important part is:
egrep -v ...
2
votes
2answers
192 views
perl regex replacing globally when global not selected
I'm using Ubuntu 11.04 and wrote a small script that searches within text files for certain "tokens" and replaces with some a prewritten snippet from a template file of the same name.
The text files ...
3
votes
2answers
691 views
Grep 'OR' regex problem
I am trying to use grep with a regex to find lines in a file that match 1 of 2 possible strings. Here is my grep:
$ grep "^ID.*(ETS|FBS)" my_file.txt
The above grep returns no results. However if I ...
1
vote
1answer
110 views
What special characters does grep parse by default? [duplicate]
Possible Duplicate:
In a regular expression, which characters need escaping?
I know there is the -E flag which treats the "search term" as a regular expression. However, it seems that even ...
6
votes
1answer
363 views
How do you save a complex regex for multiple reuse in sed?
In using sed, I often create rather complicated and intricate regexes that I need to match twice in a file. Is there a way for me to save this regex and just reference it twice?
Maybe something that ...
3
votes
3answers
168 views
What does . match?
In working with regular expressions, I have been told that a dot character . will match everything.
Except for newlines \n.
Are there any other exceptions? What about the NUL character \0, or the ...
3
votes
3answers
747 views
In a regular expression, which characters need escaping?
In general, which characters in a regular expression need escaping?
For example, the following is not syntactically correct:
echo '[]' | grep '[]'
grep: Unmatched [ or [^
This, however, is ...
4
votes
1answer
1k views
Substitute text with sed and keep part of the original text
I am trying to convert
<id>1</id>
<Name>ENTERPRISE RESOURCE PLANNING</Name>
to:
<column name="id">1</column>
<column name="Name">ENTERPRISE RESOURCE ...
4
votes
1answer
507 views
Renaming files to have lower case extensions with 'rename'
I'm trying to currently rename a large set of files and have been using quite kludgy methods to do so, such as:
rename 's:(.*)\.MOV:$1.mov:g' *.MOV
rename 's:(.*)\.JPG:$1.jpg:g' *.JPG
What I'd ...
2
votes
3answers
82 views
expr help - managing strings
I need to take text like this:
A234321=http://www.google..... a normal URL
And pull out only the URL, getting rid of the first part. I think I can use expr to do it, but I can't figure out the ...
5
votes
1answer
353 views
Why are capital letters included in a range of lower-case letters in an awk regex?
$ echo ABC | awk '$0 ~ /^[a-b]/'
ABC
$ echo ABC | awk '$0 ~ /^[a-a]/'
$ echo ABC | awk '$0 ~ /^a/'
$
You see. /[a-b]/ captures A, but /[a-a]/ or /a/ doesn't. Why?
4
votes
1answer
559 views
Is there a tool in linux that allows multi-line regex expressions?
I'm wanting to find the results of a multi-line regular expression in linux. I tried grep, but like most linux utilities it's line based.
Is there something similar that allows me to search across ...
1
vote
1answer
211 views
Regex : all greek letters with 5 unique letters (meaning that each letter only appears once)
Another one I can't seem to solve : all greek letters with 5 unique letters (meaning that each letter only appears once).
my solution :
egrep '(.)([^/1])([^/1/2])([^/1/2/3])([^/1/2/3/4])' greek.txt
...
2
votes
1answer
327 views
Regex : how to verify that there are 13 greek letters with an odd number of consonants
Another regex that I can't seem to crack :(
I tried with egrep '([qwrtzpsdfghjklxcvbnmy]{1})|([qwrtzpsdfghjklxcvbnmy]{3})|([qwrtzpsdfghjklxcvbnmy]{5})|([qwrtzpsdfghjklxcvbnmy]{7})' greek.txt
...
2
votes
2answers
427 views
Regex : match 2nd and 3rd character
I was doing some exercises on regular expressions, but I can't seem to be able to crack this one :
egrep in a file where the 2nd and 3rd character are the same.
I tried :
egrep '^..{2}' ...
29
votes
4answers
8k views
What is the difference between `grep`, `egrep`, and `fgrep`?
Can any one tell me the technical difference between grep and egrep, and fgrep and provide a suitable example?
When do I need to use grep over egrep and vice versa?
7
votes
2answers
720 views
How does a shell (bash, for example) expand regular expressions?
Assume that a directory has 100 files starting with the letter 'a'.
If I do a grep <some string> a* from the terminal, how will the shell handle this?
Will it expand the regular expression, ...
5
votes
2answers
919 views
Pattern Matching Exclude Duplicate Characters
Is there a regular expression for the following that matches characters in a character set but only once? In other words, once a character is found, remove it from the set.
If grep cannot do this, ...
12
votes
3answers
6k views
How to diff files ignoring comments (lines starting with #)?
I've two configuration files, the original from the package manager and a customized one modified by myself. I've added some comments to describe behavior.
How can I run diff on the configuration ...
2
votes
2answers
502 views
Arithmetic operations in regex
I am using gedit regex plugin (Python style regex). I would like to do some arithmetic operation on a backreference to a group.
For example:
PART 1 DATA MODELS Chapter
2 Entity-Relationship Model ...
