Regular expressions are a means of matching a pattern of characters within a string.
0
votes
0answers
2 views
I want some help into the cloudera / flume
I want some help into the cloudera / flume.
Is anyone know how to sink spool directory's .csv file data using
flume to hbase i.e splitted columns into the hbase ?
CSV File Format Data is: ...
2
votes
2answers
68 views
Find characters in the file
I need to find lines in the text file that have at least one x and at least two ys.
I tried the following:
grep -E "x.*y{2}" file.txt
This method did not work. Is there another way to do it?
2
votes
3answers
70 views
grep to find words with all vowels
Using grep -E and regular expressions I need to find words containing all of a group of characters in no particular order. For instance a word containing all vowels (aeiou) however the vowels can ...
1
vote
1answer
90 views
vim replace search text by manipulated search text
This is a very simplified version of my problem. Suppose I have a text file containing several places the code 20091a or 20092a or 20093a. I'm wishing to surround all this code by the text ...
0
votes
0answers
48 views
How to match this regular expression in bash? [closed]
I'm trying to match the sub string "~goddog" in the string "sort -u ~goddog/classes". I've defined two variables as below:
cmd="sort -u ~goddog/classes"
#eid="gogdog"
eid="goddog"
The following ...
2
votes
3answers
50 views
Yum regular expression or wildcard search?
Fedora documentation says:
5.2. Advanced Searches
If you do not know the name of the package, use the search or provides options. Alternatively, use wild cards or
regular expressions with ...
12
votes
3answers
2k views
Why does [a-z] asterisk match numbers?
I have 3 directories at current path.
$ls
a_0db_data a_clean_0db_data a_clean_data
$ls a_*_data
a_0db_data:
a_clean_0db_data:
a_clean_data:
$ls a_[a-z]*_data
a_clean_0db_data:
a_clean_data:
I ...
3
votes
3answers
141 views
Replacing a pattern in line preceding another pattern of interest
I have a log file with many instances of statements as shown below:
14 Aug 19 16:30:11.506: <DATA> |POS|IDLE|1|01131844090|5950|$hostIp|$size |$data
20 Aug 19 16:30:12.439: <DATA> ...
3
votes
3answers
112 views
Replacing string in all files found by grep. Can't get it to work
I'm trying to do what title says.
So I find all needed files with grep: grep --include=\*.{php,ini,conf,sh} -ril -P "'([\d\w\-\_\.]+)(@domain.com)'" '/var/www_data/somepath/'
Now I assume it's ...
3
votes
0answers
25 views
file(1) and magic(5) : prioritizing a result
My question follows that one: file(1) and magic(5) : describing other formats .
I want to describe a FASTA sequence ( http://en.wikipedia.org/wiki/FASTA_format)
It could be a DNA sequence (with only ...
3
votes
2answers
78 views
Extract specific set lines matching a rule
I have a large file with the logs as shown below. There are about 30000 instance of such events logged. I need to extract those lines beginning with RINGING and CLOSE (included) and which does NOT ...
4
votes
4answers
43 views
regexp which matches all tokens independent of order
I have a quick (and hopefully simple) question about regexps. I'm trying to think of a regexp which matches all of a set of tokens irrespective of order.
So for example I have a file with the names ...
-1
votes
2answers
38 views
How to remove a newline character in a particular line through perl?
I want to remove a newline character in a particular line through perl one-liner command.
Input:
1407233497,1407233514,bar
1407233498,1407233515,foo
mingstats&fmt=n
1407233499,1407233516,foobar
...
0
votes
1answer
32 views
How can I parse my String using regular expression to get only certain number of matches? [closed]
I am currently using this following regular expression to split my String into groups.
^([a-zA-Z0-9]*)(\[([a-zA-Z0-9=]*)\]){0,1}@([a-zA-Z0-9]*)$
Pty[R=4]@ID
I am getting four groups
1) Pty
2) ...
3
votes
1answer
46 views
Using sed to replace only the first two regex catches with different strings
So I'm trying to change two instances of a regex pattern to two different strings with sed like:
sed -E "s/\\t([A-Za-z]|[-])+$/\\t`get_addr.py -1`/" /path/to/file.ext
sed -E ...
2
votes
3answers
68 views
Find and change certain LaTeX coding in vim, using regular expressions?
How can I change the following LaTeX coding:
\cite{1,3-7,9}
to
\cite{1,3,4,5,6,7,9}
in vim? I would prefer to use regular expressions.
2
votes
3answers
68 views
Checking if an input number is an integer
I'm trying to check if an input is an integer and I've gone over it a hundred times but don't see the error in this. Alas it does not work, it triggers the if statement for all inputs ...
8
votes
7answers
361 views
How can I “merge” patterns in a single line?
I am doing grep and sed and I get 2 lines of a file that I am interested in. How can I get these lines in a single line ending with the new line character?
Now I am getting:
pattern1
pattern2
...
4
votes
1answer
238 views
command: ls /etc | sort | grep d* is yielding no results but ls /etc | sort | grep p* lists entire directory
I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the ...
4
votes
5answers
101 views
Insert Lines after Multi-Line Regex Match
I've got an XML file I need to append to after a specific set of tags. Basically the file structure looks like this:
<key>servers</key>
<dict>
... Server Details ...
</dict>
...
6
votes
1answer
304 views
find words with all vowels in order from a file
I have a large dictionary file with 300,000+ words in it and I'm trying to find all words with the vowels aeiou in that order and have only exactly 5 vowels. My current attempt does not seem to be ...
3
votes
1answer
35 views
Problem with regular expression in gawk ('\<' not working)
I am trying to get into bash a little bit. I was going through this guide but the second example in this subsection on gawk doesn't seem to work.
The problem is this command:
ls -l | awk ...
3
votes
1answer
44 views
Accept only y or yes with a one-line regular expression
I want to check if an input is y or yes (inputs in lowercase) and reject everything else
What I have now is ^y[e]{'0,1'}[s]['0,1']$
But this accepts y, ye, ys, yes. I don't want ye and ys to be ...
2
votes
3answers
50 views
bash: regular expressions in if expression
In my script on my ubuntu machine I declare a string like this:
DEBUG_PACKAGE_LIST=$(apt-cache search dbg | awk '{ print $1 }' | grep -e "-dbg")
For you to help you understand my problem here is ...
2
votes
4answers
85 views
Matching string with a fixed number of characters using grep
I am trying to find all 6 letter words using grep. I currently have this:
grep "^.\{6\}$" myfile.txt
However, I am finding that I am also getting results such as: étuis, étude.
I suspect it has ...
0
votes
2answers
35 views
add bracket across numbers at only end of each line
I have a file having lines as:
ram_reg_10/raja_reg_9/raghu_reg_8
abc_reg_4/bcd_reg_5
cad/pqr_reg_91
I want to convert string "_reg_number" into [number] at only last of every line in vi ...
5
votes
3answers
231 views
How to remove dot and space from beginning of filenames
I'm trying to change jpg files named with a dot and a space at the beginning and with a missing dot before the end (like this . Startjpg to Start.jpg
The dot makes the files hidden from sed and ls ...
2
votes
3answers
98 views
Reverse match in sed, replace opposite of what was found
Say I have this output from my syslog,
precalculated src_hash => 20 bytes @ 0x7f811c001e20
A6 2D E5 CD 2A BA F0 42 56 66 19 D4 61 1A E3 A0 .-..*..BVf..a...
C7 5E 5F 77 ...
4
votes
6answers
199 views
Finding the number of time a particular number in a file where range also specified
I have a file with numbers separated by ,(comma). In between it also contains a number range like 300-400. Say for example I have a text file, namely testme.txt which looks like,
...
4
votes
2answers
64 views
sed regex issue
I'm trying to replace a string in a file:
$RELEASE = '1234';
The whitespace between RELEASE and the = symbol could be either spaces OR tabs. The quotes around the version number could be either ...
4
votes
3answers
185 views
Regex alternation/or operator (foo|bar) in GNU or BSD Sed
I cannot seem to make it work. GNU sed documentation says to escape the pipe, but that doesn't work, nor does using a straight pipe without the escape. Adding parens makes no difference.
$ echo ...
1
vote
4answers
103 views
Simple sed replacement of tabs mysteriously failing
This ought to be really simple, but for some reason it is not working:
sed -i.bak -E 's/\t/ /' file.txt
Instead of replacing tab characters, it's replacing t characters. I've tried every ...
2
votes
1answer
133 views
Removing non-printable characters using POSIX sed
Files created with roff and other "old-school" tools (for example man pages on many Unix systems) generate bold and underlined text in minimalistic terminals using tricks involving non-printable ASCII ...
5
votes
1answer
616 views
Why do I have to escape a “dot” twice?
I know that we can escape a special character like *(){}$ with \ so as to be considered literals.
For example \* or \$
But in case of . I have to do it twice, like \\. otherwise it is considered ...
4
votes
3answers
120 views
Search and replace strings that are not substrings of other strings
I have a list of replacements like so:
search_and -> replace
big_boy -> bb
little_boy -> lb
good_dog -> gd
...
I need to make replacements for the above, but at the same time avoid ...
2
votes
3answers
110 views
bash - extract filenames from html file containing multiple links
I have downloaded an html file autogenerated by a script on a webpage.
The file contains multiple links, including links to images
I am trying to extract the full names of the images, for example
...
0
votes
3answers
105 views
Grep finding phone numbers in files
How would I look for files in the /etc directory (but not subdirectories) that contain a standard United States long distance phone number, written using the pattern of 1-###-###-####, where each # is ...
1
vote
1answer
29 views
awk regex matches wrong?
Playing around with awk I noticed this behavior:
[root@ror6ax3 ~]# grep open * | awk '$2 ~ /opens*/ {print $0}'
install.log:Installing openldap-2.4.23-32.el6_4.1.x86_64
install.log:Installing ...
3
votes
1answer
48 views
How do back-references match in sed?
I found a one-line sed command on this site which removes duplicate entries in $PATH. There is one concept that I can't get my mind around.
It uses saved matches in the match section to detect the ...
1
vote
1answer
59 views
Why does the same sed regex (after grep) fail when run in a bash script vs bash command line?
Here's the script. It is successful when I run it from the BASH prompt, but not in the script. Any ideas?
When I say "fails," I mean the sed regex doesn't match anything, so there is no replaced ...
0
votes
0answers
14 views
Using regex in locate [duplicate]
I would like to search for both words pdf and hack in all filenames and their paths. The order of the two words doesn't matter. I use the command locate with a regex pattern:
locate --regex ...
6
votes
5answers
236 views
Strategy to extract movies's name from this ununiform dataset?
I am working on a movie database problem to improve regular expressions, this is the problem I'm running into. My dataset looks like this:
Movie Name (variable space and tabs) year
Movie1(can ...
4
votes
3answers
332 views
Which regular expression methods to validate input could be used in shell scripting?
#!/bin/sh
re="\/$"
if [ $1 =~ $re ]; then
echo "${ATTENTION_PREFIX}$1 DIRECTORY MAY NOT CONTAIN A \"/\" OR LITERAL SLASH!${ATTENTION_POSTFIX}"
exit 1
fi
Executing sudo file.sh ...
2
votes
1answer
50 views
Context of the matching regular expression
I'm using egrep with the -o option in order to just get the matching part of the line, e.g.
cat /usr/share/dict/words | egrep -o '(aa|ii)'
Now I'd like to see some context of the match, i.e. a few ...
6
votes
3answers
211 views
Print all lines not containing punctuation
I want a regex pattern which can print all lines not containing punctuation :
Input :
.I am line 1
I am ! line 2
I am line (3)
I am line 4
Output: ( should be)
I am line 4
What I've tried so ...
2
votes
3answers
55 views
A challenge for sed convert code from Mathematica to Matlab
I have the following output from Mathematica to C code:
$ cat file.txt
Complex(1.3, 2.7)*Power(kappa, 2.0) + Complex(0.3, 2.0)*Power(kappa,5.0)*log(alpha)
The file is extremely long (many tens of ...
2
votes
1answer
88 views
sed regexp HEX char
i have this string:
echo -e "a12\x8fb12\x9f"|xxd
0000000: 6131 328f 6231 329f 0a a12.b12..
i want delete this sequence string 12\x9f and 12\x8f with sed.
i can do it with this ...
2
votes
2answers
44 views
can regex capture groups be used in GNU find command?
With the GNU find command (GNU findutils 4.4.2), a regular expression can be used to search for files. For example:
$ find pool -regextype posix-extended -regex ...
1
vote
4answers
228 views
Enclose multiple lines in quote Vim
I have blocks of the following form:
String that is not supposed to be enclosed in quotes
String that is supposed to be enclosed in quotes
String that is not supposed to be enclosed in ...
2
votes
1answer
53 views
How to match a particular form of optional sequence from a manual synopsis, including variations?
In this Q&A there is a reference to the manpages synopses being based "loosely" on the Extended Backus–Naur Form of metasyntax notation. It's interesting and serves as background. That being said, ...