Regular expressions are a means of matching a pattern of characters within a string.
2
votes
1answer
107 views
grep all words with specified length, without letter x
So I am stuck here:
grep -E '^....c...c...$' shows all words with the expr I need. Now from this words I only need the ones that don't have a x.
Who can help me?
1
vote
3answers
610 views
Print lines where first field has only four characters using regex in awk?
John Goldenrod:(916) 348-4278:250:100:175
Chet Main:(510) 548-5258:50:95:135
Tom Savage:(408) 926-3456:250:168:200
Elizabeth Stachelin:(916) 440-1763:175:75:300
output should contain the lines ...
2
votes
2answers
358 views
Removing Color Codes From Output [duplicate]
Possible Duplicate:
Removing control chars (including console codes / colours) from script output
I'm working on a script to work alongside a program that I'm writing. What i'm trying to do ...
9
votes
2answers
542 views
How to run grep with multiple AND patterns?
I would like to get the multi pattern match with implicit AND between patterns, i.e. equivalent to running several greps in a sequence:
grep pattern1 | grep pattern2 | ...
So how to convert it to ...
-2
votes
1answer
76 views
2
votes
1answer
860 views
sed special character replace not working in shell script
I want to write a script 'test.sh' that will take a user's input and replace all special characters with a '\' + the character. My script:
#!/bin/bash
echo 'input='"$1"
arg=`echo "$1" | sed ...
0
votes
1answer
259 views
Remove a block of lines between two patterns [duplicate]
Possible Duplicate:
Show only text between 2 matching pattern
In a bash script using sed how can I remove a block of lines beginning with -pattern a- and ending with -pattern b- where the ...
1
vote
1answer
214 views
Using grep command and backreferencing
This is a pretty basic question, but I can't get my head around it. I'm learning Linux and one of the questions i've been given is;
*The word sentimentalment includes the same three characters ...
1
vote
3answers
159 views
find with user variables
I am trying to call find with a few variables. So far I had this:
DIRECTORY="./ "
FILENAME=-regex" .*test.*"
find $DIRECTORY $FILENAME
Which works fine. If I change the filename to :
...
1
vote
4answers
335 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
306 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
3answers
737 views
remove white space before delimiter with sed
I have data of the following format that I want to input into LibreOffice calc
data | num | num | num | num
For some reason Libreoffice does not think the string "3214 " is a number by ...
1
vote
3answers
255 views
Compacting `find` name patterns
I am using
find . -name '*.[cCHh][cC]' -exec grep -nHr "$1" {} ';'
find . -name '*.[cCHh]' -exec grep -nHr "$1" {} ';'
to search for a string in all files ending with .c, .C, .h, .H, .cc and .CC ...
1
vote
2answers
115 views
Match a simple Regex
I need to match this: (tt\d{1,10}) in a file with the file ending txt.
I have tried grep and ack-grep but without results.
ack-grep -G \.txt$ -g "(tt\d{1,10})"
2
votes
4answers
332 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 ...
11
votes
6answers
358 views
How can I grep a directory based on the contents of two successive lines?
How can I grep a directory for lines that contain "Foo", but only get matches when the next line also contains "Bar"?
3
votes
3answers
1k 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
830 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 ...
0
votes
1answer
370 views
Asking ls to only list files in a path that match a specific glob/regex
In Zsh: Is there a way to use ls to only list files and folders in the current directory that match a specific globbing or regex pattern?
For example, say I have multiple files that start with the ...
2
votes
3answers
291 views
Find word in sentence with Bourne Shell (sh)
I'm trying to determine if a particular word appears in a sentence using Bourne Shell (sh). For example:
#!/bin/bash
INPUT='Lorem ipsum dolor sit amet.'
if [[ "$INPUT" == *dolor* ]]
then
echo ...
2
votes
2answers
547 views
Replace the shortest match of a string pattern
I have this string:
update mytable set mycol=myvalue where mycol=yourvalue;
I need to convert it to:
insert into mytemp select * from mytable where mycol=youvalue;
I can accomplish it like this ...
1
vote
1answer
443 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
282 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 ...
4
votes
1answer
162 views
Emacs simple arithmetics in query replace
Is it possible to do the following in emacs:
Query replace all numbers in a region by the number +n, for example if you have:
12 and 7 are nice numbers
let n be 3, then it should transform to
15 ...
0
votes
1answer
103 views
awk extended pattern matching (embedding pattern matching in actions for already matched strings) [closed]
I want handle strings of the form:
PREFIX_TYPE_N,DATA
So, does the *awk (gawk, mawk, nawk) support including pattern matching in the action for already matched string? Something like this (of ...
1
vote
2answers
256 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
...
2
votes
2answers
216 views
AWK match string, not Regex
How do I match a string with AWK?
Say I have the string [(*.+ it should only match strings containing the string [(*.+.
The string is entered by the user, so if you know a cli utility that can ...
0
votes
5answers
1k 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
495 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
2k 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
106 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
219 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
187 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
333 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 -> ...
3
votes
2answers
113 views
Do procmail recipes have an alternator “or” operator?
Given the following procmail recipe:
:0:
* ^Subject:.*viagra.*
* ^From:.*viagra.*
/dev/null
Procmail would only delete emails that were both from viagra, and had viagra in the subject. Is it ...
2
votes
1answer
112 views
prepend digit to filenames which begin with digits (with zmv, please)
I have a directory with files named like 19.png, 20.jpeg, and README00.txt
I want to rename these to 119.png, 120.jpeg, and README00.txt.
I would like to do this with zmv as it works well in so many ...
1
vote
1answer
43 views
cclive: what kind of regexes are allowed?
Is there a place where I can look, what kind of regexes I can use with the --tr option from cclive?
5
votes
3answers
198 views
VIM see regular expressions matches as you type
If I type /regex then the cursor temporarily jumps to the first match and all matches are highlighted. This updates as I type. Is it possible to get this behavior when I'm getting ready to make a ...
2
votes
1answer
205 views
How to join vCards lines
vCard uses a special way to split long lines: At 75 characters, insert a DOS newline and a space. Joining therefore means to replace all occurrences of the sequence "CR, LF, space" with an empty ...
2
votes
2answers
389 views
Sort by regular expressions
I've got a set of POSIX regular expressions*
^BEGIN:VCARD\r$
^VERSION[^A-Z]
^FN[^A-Z]
^N[^A-Z]
^NICKNAME[^A-Z]
^EMAIL[^A-Z]
^X-\([A-Z-]*\)
^TEL[^A-Z]
^ADR[^A-Z]
^ORG[^A-Z]
^TITLE[^A-Z]
^BDAY[^A-Z]
...
2
votes
2answers
497 views
How to do a regex search in a UTF-16LE file while in a UTF-8 locale?
EDIT: Due to a comment Warren Young made, it made me realize that I was not clear on one quite relevant point. My search string is already in UTF-16LE order (not in Unicode Codepoint order, which is ...
2
votes
1answer
224 views
Emacs: query-replace, regular expression, reuse of search result
How do I combine something like query-replace with a regular expression search-and-replace that in part reuses the search result?
In my case, how to transform
The programmers are "sort of" ...
0
votes
2answers
161 views
Difference in regular expression handling between Perl, Kikki, and Kodos
#!/usr/bin/perl
$mystring = "[2004/04/13] The date of this article.";
if($mystring =~ m/(\d+)/) {
print "The first number is $1.";
}
Perl returns 2004, but Kiki and Kodos return /04/. Why ...
1
vote
2answers
287 views
Weird zsh grep -P behaviour
I connect to server with PuTTY from Windows.
I have a long yet not touched (I suppose) by hands of local admin config:
$ cat /opt/jira/.subversion/config
...
### must be enabled, which is ...
13
votes
5answers
573 views
How to remove the (1) from filenames using the find command
I recently converted all of my FLAC files to a lower sampling rate of 44.1 kHz and bit depth of 24 bits (because iPhone/iPod don't support anything above that) using XLD on my Mac OS 10.7 (Lion).
...
0
votes
1answer
93 views
Replacement in VIM with regular expression matched part unchanged
Suppose I want to append two digit numbers in my file with "some_thing".
Like from this:
12 23 45
to
12_something 23_something 45_something
How can I do this using regular expression ...
2
votes
2answers
249 views
Detect pattern repetition in a file
I want to make sure a file follows the following pattern:
... ... ... foo ... foo_KO ... ...
... bar ... ... ... ... bar_KO ...
The file is extremely long, so, in other words, I want to make sure ...
1
vote
2answers
156 views
How do I generate a list of the characters occurring before a certain character only in lines that contain another certain character using regex?
I know that's super confusing (total noob-sorry!). To clarify, I have a text file that looks like this:
407-OL?
408-2-OL?
408-OL?
418-het?
420-1 and 2- OL?
429-2-left unscored?
430-2-left both ...
3
votes
1answer
159 views
match files based on an md5 using find
I have a bunch js and css files in a directory. Some of them have been given a name based on an md5() of their content (looks like f10521a21bb013cb81e0909809818ad6.js). I'd like to match these files ...
3
votes
1answer
616 views
escaping a single dot with double backslash - awk
"effective awk programming" book has an example on Field-Splitting. here is the example:
If you want fields to be separated by a literal period
followed by any single character, use ‘FS = ...

