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,"*",...