Regular expressions are a means of matching a pattern of characters within a string.
1
vote
4answers
56 views
Replace text between brackets
I'm using awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }' to replace text in data like:
SOMETHING [BAR, WIBBLE]
SOMETHING [BAR]
This gives the desired result of:
SOMETHING [FOO, FOO]
SOMETHING [FOO]
...
2
votes
2answers
41 views
Parse apache logs to exclude IP ranges
I need to look for some requests in a huge pile of apache logs. My only requirement is this:
I need to only view the requests coming from any IP address that is NOT included in a list of 50 IP ranges ...
2
votes
4answers
95 views
Change currency format to generic number using sed
I am working on a large csv file with all coma separated entries. The entire document is composed of plain numbers, except for a few columns reflecting currencies that are formatted as text. For ...
2
votes
3answers
154 views
AWK - how to reduce the greed of a regular expression?
I have an example:
echo "@article{gjn2010jucs, Author = {Grzegorz J. Nalepa}, " | awk '{ sub(/@.*,/,""); print }'
Is it possible to write a regular expression that selects the shorter pattern?
...
11
votes
3answers
437 views
Online grep exercises?
Are there any online grep tutorials that would feature some online tool for performing exercises? For example, having some predefined text sample and being told what patterns to find and so forth? It ...
1
vote
1answer
135 views
Regular expression how to get value in shell script?
I have to write a shell script to get value from a string .. something like that :
string="abcdef" pathName
How can I use "grep" command with the use of regular expression to get "pathName" ? Thank ...
2
votes
3answers
76 views
with sed, how can I replace word within a matching line?
I am trying to write a sed expression to detect lines similer to this:
s0:12345:respawn:/sbin/agetty -8 -s 115200 ttyS0 linux
and replace the "ttys0" with "something_else"
I do not want to detect ...
1
vote
2answers
128 views
How to find and replace files contents that match a pattern?
Suppose we have a folder named Project.
I would like find each file in the folder that contains the pattern &$
at the function call.
For example should replace:
AnyFunction(&$arg);
with
...
0
votes
5answers
232 views
(Mac Terminal) sed to parse JSON … what am I doing wrong?
In Mac Terminal, I'm trying to parse the "name" out of this JSON response:
{"created_at":"2012-08-27T20:04:27Z","deleted_at":null,"id":21462840,"item_type":"video","name":"CastingBy-v12
...
8
votes
2answers
387 views
What is the definition of a regular expression?
I recently got into a friendly argument with Ghoti about what constitutes a regular expression in the comments to my answer to this question. I claimed that the following is a regular expression:
...
2
votes
4answers
188 views
How can I find all files in a folder that contain a match of a regular expression in the file name?
I'd like to find all of the files in my home folder on Linux (Ubuntu, in this case) that contain a match a particular regular expression. Is there a simple Unix command that I can use in order to do ...
4
votes
1answer
70 views
Using Regex in vim movment
Is there any way to use regular expression for movement in vim. For example,
I want to move my cursor to the first occurrence of the pattern abc. So can I do something analogous to fa but now a ...
3
votes
4answers
121 views
Sort input file by the results of a regex
I'd like to sort a file based on the results of a regex expression. For example, if I have the following property declarations in Obj-C
@property (nonatomic, strong) id <AlbumArtDelegate, ...
3
votes
2answers
113 views
Find and regex
What am I doing wrong with this find expression?
; touch ook ooks
; find . -name 'ook' -or -name 'ooks' -type f
./ook
./ooks
; find . -name 'ook[s]?' -type f
[returns nothing]
; echo $?
0
1
vote
4answers
220 views
Stripping all vowels but the first from a set of strings
I have a string comprised of multiple substrings, separated by underscores. For example: AbcdAEfd_hEgdgE_AbAAAAA. I need to remove all vowels except the first from each substring. So:
AbcdAEfd -> ...