Regular expressions are a means of matching a pattern of characters within a string.
2
votes
1answer
32 views
Trouble getting regex to work with find
I'm having a lot of trouble getting find to work with regex flags. Im using egrep on its own to find a date pattern in a file, like this:
egrep '[0-9]{4}-[0-9]{2}-[0-9]{2}'
which will return dates ...
1
vote
0answers
11 views
lftp exclude syntax confusion
I am confused with the syntax description given for lftp from their website:
-x RX, --exclude=RX exclude matching files
-X GP, --exclude-glob=GP exclude matching files
How ...
1
vote
1answer
30 views
How to Replace Path in Search field using VIM
I'm trying to replace this text in VIM
Actual Path /home/omipenguin/Servers\ Information/systemscript.sh/sysinfo.txt
with this new path
/home/sysinfo
I tried
%s/\/home\/omipenguin\/Servers\ ...
5
votes
2answers
69 views
Lowercase all but the first (Uppercase) letter from UPPERCASE in cyrillic
To make all letters a lower case except the first letter. The first letter would look like "Uppercase" after I changed (from UPPERCASE in cyrillic). The rest (not UPPERCASED) leave unchanged.
I'm ...
8
votes
2answers
286 views
Regular expression in bash script
This is my first time bash scripting so I'm probably making an easy mistake.
Basically, I'm trying to write a script that gets the groups of a user, and if they are in a certain group, it will log ...
3
votes
3answers
57 views
Using a perl compatible regex with GNU grep -P
I'm using this regex (?<=\[')[^,]* on a file containing the following line disk = ['OVS/sdasd/asdasd/asdasd/something.img, w']
I want that to return OVS/sdasd/asdasd/asdasd/something.img
How do I ...
1
vote
1answer
43 views
Brace expression does not work in find regex
I have two folders, CA01 and CA02 under current folder, foo:
foo -+
|
+-CA01
|
+-CA02
When I type
find . -regex ".*CA[0-9]+" -exec echo {} +
Or
find . -regex ...
1
vote
2answers
45 views
Why `rename` behaves differently whenever I use full path instead current path?
Ok, I'm answering a question where the OP have several repositories in Ubuntu that might be causing a problem installing unrelated software. I recommend disabling the PPA's using a single liner rename ...
3
votes
1answer
73 views
Get all regex matches between two patterns and print them to file
I've got a file with a bunch of long lines. I'd like to grab every group between two patterns and print them to a new file, one match per line. I could manage to do this with Python, but I'd prefer ...
2
votes
1answer
34 views
Regex to find NFS filesystems that aren't being mounted with nosuid, except for ones with special needs
I have a script that runs the command mount -v 2>/some/file, which I then parse with another script using the following regex:
^.*[\ \t]+type[\ \t]+nfs(?![\ \t]+.*\b(?:nosuid|nosetuid)\b).*
The ...
0
votes
2answers
50 views
grep + operator
According to the grep manual:
* The preceding item will be matched zero or more times.
+ The preceding item will be matched one or more times.
Let's test it
echo 'agb' | grep 'a.*b' # returns ...
0
votes
2answers
15 views
How can I reformat tabular data using AWK?
I have a file contain following output.
ora.abc.db
1 ONLINE ONLINE serverA Open
2 ONLINE ONLINE serverB Open
ora.xyz.db
1 ...
4
votes
2answers
83 views
VIM substitute occurrences of pattern after a particular word in a line
I have such lines in my text.
text before pattern = garbage** text after pattern is pattern
If in VIM I do %s/pattern/saturn/ it replaces all occurrences of pattern. But I only want to replace ...
2
votes
4answers
60 views
Alternative regex for {}
I am trying to replace all of this line, but the numbers:
looktype="123"
so only the numbers show up.
Is this possible in any easy way?
{sub ("look type=\"[0-9]{0,3}", "TEST")}
I am trying this ...
1
vote
1answer
32 views
How to match a literal '*' with sed?
I have this line in my file called test.php
'dbs_password' => 'a8b*cyP0',
and want to replace into:
'dbs_password' => 'password-here',
So I use this sed command with syntax:
$ sed -e ...
1
vote
2answers
46 views
Pattern repetition and regexp
Take the pattern
[UGLER]*
Can the string UUG match against it? I mean to say, is repetition allowed?
2
votes
2answers
89 views
regular expressions with grep
I have this command right here:
grep -B10 -A10 '14:14:50 {"channels":["/alerts/6979/new"],"data":"New alerts for unit 6979"}' mygateway.log
Rather than searching for 14:14:50 I would like the 50 to ...
1
vote
3answers
47 views
Stuck in separating chars into strings in my approach. Found a working approach but can not understand it
I am trying to figure out how to break a string to be on character per line.
I.e ahebhaaa to be:
a
h
e
b
h
a
a
a
I tried:
$ echo ahebhaaa | sed 's/\(.\)\(.\)/\1\n\2/g'
I.e. my ...
4
votes
2answers
87 views
Why do I need to escape regex characters in sed to be interpreted as regex characters?
It seems e.g.
cat sed_data.txt | sed 's/\b[0-9]\{3\}\b/NUMBER/g'
that I must escape characters to form a regular expression. In this case I had to escape braces in order to be interpreted as a number ...
3
votes
3answers
85 views
vim search numbers containing specific number of digits
I need to find specific length numbers in a big document. I tried to use regex for this. For example, If I need to search for numbers with exactly 2 digits, I use /d/d (i.e. /d twice followed by a ...
1
vote
2answers
41 views
sed : Ignore line starting whitespace for match
I want to replace the default listening port of httpd to 9090. I can edit the line in httpd.conf file using below
sed -i "/^Listen/c\Listen 9090" /etc/httpd/conf/httpd.conf
But the line
Listen 80
...
1
vote
3answers
70 views
grep for an alphanumeric strings of any length with a colon on each side
How would you grep for an alphanumeric strings of 1 to 50 characters (ideally, any length would work too) with a colon on each side – a typical result would be all the lines containing the string ...
2
votes
1answer
62 views
How to insert both vimscript variable and string into vim search and replace
I've only just found out about Vimscript's existence as of today, so forgive me if this question is more basic than it seems, but I've been struggling to find an answer to this question for the better ...
1
vote
1answer
36 views
Aptitude regex engine
I was trying to lookup the versions of libdb in the debian archives with something like that:
$ aptitude search '~S~ndev$(~nlibdb~(\d~|-~)!~v~rnative)'
which didn't work as expected so I changed ...
0
votes
4answers
110 views
Match multiple regular expressions from a single file using awk
I'm trying to parse a HTML file using shell scripting.
There are 4 different regular expressions that i need to catch: name= , age= , classs= , marks=.
Using
grep "name=\|age=\|class=\|marks=" ...
1
vote
2answers
63 views
How can I combine grep with file and extra regex
I have a file of strings in each line.
For example:
AAAAA
BBBBB
CCCCC
etc
I want to check each string one by one whether it exists in a series of files in a specific directory.
I ...
1
vote
4answers
77 views
Regexp on data flow
I want to test if in my data flow, there is something, and do an exit code.
I use gammu monitor, which provides a data flow, for example :
[root@MYSERVER ~]# gammu monitor
Press Ctrl+C to break...
...
4
votes
4answers
325 views
How to grep for pipe |
How can I grep for line containing pipe character | or for character >:
files content:
|this is test
where is >
this is none
now what I need using grep command is
grep -iE "<some ...
1
vote
3answers
80 views
Escaping * with Regular Expressions and Grep
I have a file that has unique lines that start with 2 stars (**).
However when I run a grep command for
grep \*\* fileName
I get all of the lines in the file. This is very unusual, and what I ...
1
vote
4answers
103 views
Can tr work with regex?
I have a file like this:
AAAA
BBBB
CCCC
DDDD
etc
Words in separate lines. I want to add them quotes using tr.
So I tried the following:
1) To add a quote in the start of each word ...
1
vote
3answers
80 views
Remove 2 and 3 newlines in a text file but not 1
I'm developing on a max osx 10.8 and have no preferences to which tool to use probably sed but it doesn't matter.
Update after comment:
The input file uses windows new lines if that's complicates ...
1
vote
1answer
78 views
Why is this line included in the `logcheck` report email?
In addition to the Debian provided rulesets, I have added a file /etc/logcheck/ignore.d.workstation/wpasupplicant.local (owner root:logcheck, mode 0644) to my newly installed logcheck setup. I have ...
4
votes
1answer
71 views
grep: display filename once, then display context with line numbers
Our source code has error codes scattered throughout. Finding them is easy with grep, but I'd like a bash function find_code that I can execute (eg. find_code ####) which will provide output along ...
1
vote
1answer
61 views
vim regex to search for lines containing string1 AND string2
How in vim/vi can I search for all lines that contain string1 and string2, where either string can appear anywhere on the line separated by whitespace and possibly other words?
I would also like to ...
2
votes
3answers
69 views
Pulling out keywords using standard command line utilities?
As an example, this is the pronunciation of "when" according to Wiktionary. enPR, IPA and X-SAMPA are different schemes for showing pronunciations.
when:* {{a|US}} {{enPR|wĕn|hwĕn}}, ...
5
votes
1answer
105 views
Execute a command within 'sed'
I have a list of random memory addresses saved in a text file, and I need to sed them out, decode them, and save them back to my file. However, the decoding operation I'm trying to perform is handled ...
3
votes
4answers
122 views
Replace all occurences of \ except \N
I have a file like this:
1,2,subjects,\mat\hs,unix\,\Nato,\N,123,\N
I want to replace all occurences of \ with #, except for \N, such that the output looks like this:
...
2
votes
3answers
72 views
mv files to a different path which is constructed via a regex replacement
I have a directory full of files stored in subdirectories according to their filename, i.e.:
20d1/d325/52d1/20d1d32552d1a95249e62662fbdf924dd72c4027.jpg
...
1
vote
2answers
63 views
Backreferencing with sed
I have a database containing a list of unsigned longs representing a bunch of memory addresses followed by an offset within two brackets (e.g. Mem[offset], 0x2322AD4[3]), and some other data. What I ...
1
vote
2answers
82 views
Tell a regex expression to skip the beginning of a line before matching
If I had a string like 45mb ./aaaa/bbbb/cccc/dddd and I use a regex like [^\/]*\/ it will match 45mb ./aaaa/bbbb/cccc/
I only want it to match ./aaaa/bbbb/cccc/ but I can't figure out how to do ...
2
votes
1answer
168 views
Forcing Bash to use Perl RegEx Engine
As you may already know, a lot of the features modern RegEx engines support (back referencing, lookaround assertions, etc.) are not supported by Bash RegEx engine. Following is a simple Bash script I ...
1
vote
1answer
58 views
What are the commands that you can use in the beginning of a sed command?
I initially learned to do sed search and replace like so:
sed -e 's/<stuff>/<replacement>/'
However I recently learned that these will do something different based on what command ...
1
vote
4answers
192 views
Change filename from lowercase to uppercase recursively
I have 1,000,000 files in some folders and subfolders. I want to rename them from lowercase to uppercase using shell commands. I don't want to modify the extension. only filename part.
I have found ...
1
vote
4answers
97 views
using simple regex quantifier expression in grep
Does anyone know why ls | xargs -n 1 basename | grep -E '[0-9]{1}' does not only show occurrences of a single digit between 0-9?
For example if I have:
touch 1
touch 22
touch 333
touch test_file
...
3
votes
3answers
110 views
How can I grep for this or that (2 things) in a file?
I have a file that has "then"'s and "there"'s.
I can
$ grep "then " x.x
x and then some
x and then some
x and then some
x and then some
and I can
$ grep "there " x.x
If there is no blob none ...
1
vote
2answers
61 views
Grep and regex, Why does the following return only a specific portion?
Why in the following:
echo this is a line. | grep -o -E "[a-z]+\."
The result is line. and not this is a line.?
There is no word boundary or any other restriction on the regex.
2
votes
1answer
69 views
How to negate a regex inside another regex
That is, given a POSIX regex X, what POSIX regex is the complementary of X? (in a more detailed way: how to get regex X' that matches all strings that are not matched by X, but doesn't match any ...
0
votes
3answers
69 views
Removing second colon
Trying to create a simple script that lists mass mailing by the queue number that appears in /var/log/maillog. I'm starting off with this:
[root@ditirdlns01 ~]# lsMails(){ grep -i ...
1
vote
3answers
245 views
extract part of string using sed
ls lib/oracle-11.2.0.3.0.txt | sed 's/lib.\([oracle.*]\)\.txt/\1/'
It is giving the whole string instead of just oracle part until .txt What am I doing wrong?
I can do it using awk as follows, but, ...
0
votes
4answers
66 views
Use grep with or [duplicate]
How do I search in a textfile with grep for the occurrence of a word or another word?
I want to filter the apache log file for all lines including "bot" or "spider"
cat ...