Skip to main content

All 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
user3634569's user avatar
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 ...
togo's user avatar
  • 13
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 ...
spiridon_the_sun_rotator's user avatar
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 ...
Magi's user avatar
  • 1
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....
jxhyc's user avatar
  • 181
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) ...
myc3lium's user avatar
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 ...
bit's user avatar
  • 1,116
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 [[ $...
user avatar
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 ...
vfclists's user avatar
  • 7,619
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" =~ ...
gzc's user avatar
  • 325
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 ...
Nullpointer's user avatar
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 ...
OJFord's user avatar
  • 1,995
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 ...
MathMan's user avatar
  • 181
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-...
ivand58's user avatar
  • 125
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?
tmpbin's user avatar
  • 783
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: ...
user164723's user avatar
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 ...
romil gaurav's user avatar
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 #...
kris's user avatar
  • 163
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 ...
BluVio's user avatar
  • 155
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 ...
Sudhish Vln's user avatar
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 ...
Katz's user avatar
  • 1,071
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 ...
kevinarpe's user avatar
  • 687
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 ...
user53029's user avatar
  • 2,843
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 ...
user avatar
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])
Rishabh Verma's user avatar
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' *#~\!&*() $
LoukiosValentine79's user avatar
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 ...
ironsand's user avatar
  • 5,265
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 ...
ZengJuchen's user avatar
  • 7,677
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(...
Chaos_99's user avatar
  • 123
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,"*",...
dr.doom's user avatar
  • 111

15 30 50 per page