All Questions
Tagged with quoting regular-expression
52
questions
-1
votes
1
answer
42
views
I can't grep some inputrc string
bind -p |grep -E "\\e.\":" work
but
bind -p |grep -E "\\e\\C-.\":" don't work
I tried a lot of combination
1
vote
1
answer
3k
views
How do I quote square brackets in Ansible variable value for regexp parameter?
I use the ansible.builtin.lineinfile module to modify a PHP-FPM pool configuration file. How should I quote the square brackets (annot.: or other special characters) in a value of a variable for the ...
1
vote
0
answers
101
views
How to move all the files with specific prefix of the directory? [duplicate]
I have a following directory structure (assume no two files have the same name):
Apple1
apple1.jpg
apple2.jpg
Apple2
apple3.jpg
apple4.jpg
Apple3
Tomato
Peach
And i would like to move one ...
0
votes
1
answer
90
views
Putting single quote in the begining of column
I have a .txt file with publications for which columns are separated by a single space.
However, titles also have spaces an in order to separate the columns correctly I need to have all titles in ...
1
vote
1
answer
2k
views
grep: use square brackets to match specific characters
So I am experimenting with the power of grep using this resources
The problem I am currently encountering is that it doesn't seem to work as I intended. so I have an demo.txt file that contains foo....
2
votes
1
answer
180
views
awking for command options from man page
I am trying to auto-generate tab-completions for different commands. I am piping man pages for different commands into awk, then searching for command line options (eg. -shortopt --long-option) ...
5
votes
2
answers
26k
views
How do I grep multiple patterns from a pipe
I want to find three patterns in a list. I tried typing
$ pip3 list | grep -ei foo -ei bar -ei baz
but the shell throws a broken pipe error and a large Traceback.
How do I grep for multiple ...
1
vote
0
answers
2k
views
Why use a variable in a bash regex match inside [[? [duplicate]
There is not a simple answer to this question at this site yet.
This question aims to give a simple and clear answer.
It is usually recommended to use a variable ($regex) in this construct:
if [[ $...
4
votes
3
answers
15k
views
How can search for both single quotes and double quotes in a grep search?
When I do a search bindkey in the zsh plugins directory for key conflicts I get responses from both the .zsh script files and .md files, and some of the zsh readme files use a double quote in the ...
10
votes
3
answers
17k
views
shell test whether multiple lines string contains specified pattern in last line
I want to determine whether a multi-line string ends with a line containing specified pattern.
These code failed, it doesn't match.
s=`echo hello && echo world && echo OK`
[[ "$s" =~ ...
0
votes
1
answer
2k
views
Print a variable in single quote on bash | Weird Variables
On bash script, I need to pass date as ansible extra variable but getting something single quotes related issues;
...
$DT="03-04-17"
ansible-playbook copy2s3.yml --extra-vars 'cdate={{ "$DT" }}'
and ...
0
votes
1
answer
344
views
\1 in sed command not working under xonsh
I don't understand what I'm missing here:
$ echo 'testing' | sed -E 's/([a-z]*)ing/\1ing/g'
ing
I would expect the output to be testing again, since \1 should be test? That input seems to have been ...
0
votes
4
answers
4k
views
Regular expression within single quotes- lose their value? [closed]
The book I am reading - Learning the Bash Shell by O'Reilly specifies some code as follows:
if [ -n "$(echo $1 | grep '^-[0-9][0-9]*$')" ]; then
howmany=$1
shift
....
....
etc
...
1
vote
3
answers
205
views
how to filter inner quotes? [closed]
is it possible to filter, i.e to put ESC in front of the inner quotes with sed, awk or other *NIX tool (no perl/python)?
Example (revised):
$ echo label=\"123 \"456\" 789\" \"AB C\" e f gh | magic-...
9
votes
1
answer
1k
views
Why does `grep fil*` fail?
I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds.
I don't understand it, can someone explain?
3
votes
2
answers
4k
views
Define a variable to awk pattern matching from bash
I am trying to grab 100 lines after the text "time: X" with X in {0,40,80,...,200}. Here is what I have so far:
#!/bin/bash
start=1
end=5
for i in $(seq $start $end);do
j=$(($i*40))
awk '/time: ...
2
votes
4
answers
6k
views
Why does the grep command ignore the period in the search string?
The command that I am using:
find . -type f -name "*.sql" -exec grep -i -l 'schema_name.' {} +
What I want to search is all the files which contain schema_name..
But the find command is ignoring the ...
1
vote
1
answer
2k
views
regular expression : with a variable
arrFormat=( jpg jpeg bmp tiff png )
varExtension="jpg"
for elem in "${arrFormat[@]}"
do
echo "${elem}"
# do something on $elem #
done
#for i in $( find -E . -iregex '.*\.($arrFormat)' ) ; do #...
3
votes
1
answer
3k
views
cshell alias: How to use nested single quotes(') in in cshell alias
I am trying below alias in cshell:
alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l'
For this CSH says, Illegal variable name.
If I use \$, alias will be set without any error. But ...
0
votes
3
answers
838
views
significance behind escaping parentheses in expr match
Can anybody give me the difference between the following two commands in the context of escaping parentheses, or refer some document that would clear my doubt.
string=abcABC123ABCabc
$ echo `expr ...
1
vote
1
answer
3k
views
What does a backslash represent when searching for decimals
I want to understand what the backslash represents in this command. grep "\.900983" table
I know what the command does, it searches for the 900983 value in table, I'm just not sure of the purpose of ...
3
votes
2
answers
2k
views
How to escape metacharacters for egrep like metaquote from Perl?
Perl has a function called metaquote() to escape all special characters for a regular expression.
Is there an equivalent technique for egrep?
Example: If I am searching for the string abc.def.ghi, I ...
0
votes
0
answers
358
views
swap strings of text inside vim using regex
I am working with a file where I need to swap "string A" and "String B's" locations simultaneously with a regex inside the vim. Here is an example line of code:
succ_1st=`grep 'resulted in successful ...
4
votes
1
answer
1k
views
Match pattern \\\" using grep
I have a json string inside json. This got encoded multiple times and I ended up with many escape backlashes: \\\".
The much shortened string looks like,
'[{"testId" : "12345", "message": "\\\"the ...
0
votes
1
answer
264
views
What does "\(\)" stand for in this command: grep("-(mean|std)\(\)", x[,2])
Need to know about the function of \(\) in grep("-(mean|std)\(\)", x[,2])
6
votes
1
answer
678
views
Why can't I escape the braces "]" in sed?
Question: Why can't I escape the "]"?
$ printf "*#$@~\!&*()[]\n"
*#~\!&*()[]
$ printf "*#$@~\!&*()[]\n" | sed 's/[*#$@~!&*()\[\]]//g'
*#~\!&*()
$
1
vote
2
answers
2k
views
How to search parenthesis by ack
I want to search for a parentheis ( using ack, but neither using ( nor \( worked.
The first one ("(") is recognized as a multiple line command.
The second one ("\(") is treated as an invalid regular ...
3
votes
3
answers
703
views
Why awk understand FS="*" but not for FS="-*-"?
I got a test file, its content is:
a -*- b
I used awk 'BEGIN {FS="*"} {print $2}' test, it prints out
- b
Correct! But when I use awk 'BEGIN {FS="-*-"} {print $2}' test, I got:
*
I know that FS ...
1
vote
2
answers
2k
views
Why does regex with \\$\{ work with egrep, but not with sed?
Given a text like this
./RFF_09 -f${FILE} -c${COND}
inside a file, this egrep command will correctly match:
egrep './RFF(.*) (.*)-c\\$\{COND\}' file
but this sed command will not
sed -n "s:'./RFF(...
1
vote
0
answers
76
views
Take the unknown contents of variable as literal in sed [duplicate]
I have two files: a.patterns contains patterns in a one per line way
"`"
"^"
"<"
"<("
"<)"
"<["
"="
">"
"_;|^+*+?@"
and b.data contains comma separated values.
1,1,0,"*",1
2,1,1,"*",...
6
votes
3
answers
2k
views
Why does my grep expression need to use $'string' to match tab characters?
If you take this code:
echo -e '\t\t\tString' | grep '^[\t]*String'
the result is blank because it doesn't match, yet this:
echo -e '\t\t\tString' | grep $'^[\t]*String'
works. I swear that I must ...
1
vote
1
answer
7k
views
How to escape unbalanced brackets or slash in sed?
I'm trying to use sed, but my pattern contains [] brackets and slashes (/).
I've tried quotes, but it doesn't help.
How do I escape it?
Examples:
$ sed -i'.bak' "s/^includes[] =/;includes[] =/g" *...
10
votes
4
answers
6k
views
Regular expression using \\ vs using \
Why does
grep e\\.g\\. <<< "this is an e.g. wow"
and
grep e\.g\. <<< "this is an e.g. wow"
do the same thing?
If I add a third slash, it also has the same result. BUT, once I ...
2
votes
1
answer
2k
views
Regex works in shell but not through Perl script
I'm having trouble executing a Perl script through the Unix shell using Perl's system command.
I've had more complex regex commands I had to adjust accordingly to convert from Unix to Perl, and they'...
72
votes
11
answers
235k
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 (numbers/letters)...
5
votes
1
answer
7k
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 ...
17
votes
2
answers
24k
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 ...
8
votes
5
answers
15k
views
bash event not found trying to match and exclude parenthesis in grep
In a very long line I'll summarize with:
(foo),(bar,baz(word,right),(end)
I want to print only:
(bar,baz(word,right
To match the second parenthesis, I exclude the word that follows the third ...
10
votes
3
answers
51k
views
Why can't find -regex match a newline?
Why does this fail?
touch "$(printf "a\nb")"; find . -regex './.\n.'
I also tried these, none of which work:
find . -regextype posix-extended -regex '.\n.'
find . -regextype posix-awk -regex '.\n.'
...
1
vote
2
answers
3k
views
Why is my grep + regex not working?
I recently decided that enough was enough -- I was going to learn to use grep fluently. It's been all of three hours and I'm already stumped by this toy problem.
I'm currently syncing a RAID5 array, ...
8
votes
2
answers
31k
views
"grep: Unmatched [" error when using regex
I'm trying to find a pattern similar to this:
tail -n 100000 gateway.log | grep -B10 -A10 'Nov 22 11:13:56 Received Packet from [10.50.98.68'
Where "11:13:56" could be any time.
This is what I came ...
2
votes
2
answers
1k
views
What does this regex mean?
I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex
sed 's/$'"/`echo \\\r`/" input....
13
votes
2
answers
5k
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 ...
16
votes
4
answers
39k
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 ...
8
votes
3
answers
33k
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 see ...
228
votes
7
answers
723k
views
Using sed to find and replace complex string (preferrably with regex)
I have a file with the following contents:
<username><![CDATA[name]]></username>
<password><![CDATA[password]]></password>
<dbname><![CDATA[name]]></...
3
votes
1
answer
192
views
find utility does not recognize bracket notation
I've two files in the current folder:
submitWeb.m
submit.m
the following find does not show the two files:
find . -regex .*submit\(Web\)?\.m
But the above regex expression works fine in emacs ...
4
votes
2
answers
56k
views
How to tell grep to match special character at beginning of each word [duplicate]
I have certain questions regarding grep.
Why does the following command match '<Hello'?
$ grep -E "\<H" test
Hello World
<Hello
H<ello
What needs to be done to match '<Hello' only?
1
vote
2
answers
3k
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 ...
806
votes
13
answers
1.8m
views
How do I grep for multiple patterns with pattern having a pipe character?
I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing
grep (foo|bar) *.txt
but the shell interprets the | as a pipe and ...