All Questions
59
questions
0
votes
1
answer
79
views
How to use grep string that has double quotes in it
So I'm running a simple alias called vpn which runs a command and has an output, which I put into a .txt file.
If interested to what exactly then here is the alias
alias vpn="docker exec -it ...
-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
votes
3
answers
94
views
How to use a variable in a command inside of a bash file
I use this command directly on our redhat linux server 8.8 and it's working correctly and I get the result I want:
grep '01-FEB-2024' /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ...
3
votes
1
answer
7k
views
Grep pattern that has double quotes and variable substitution surrounded by single quotes
So, Let's say I have the following pattern:
Thisisatest="1"
in a file called file.
And I want to match the exact string above but for whatever reason, I choose to loop over some numbers ...
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....
3
votes
1
answer
2k
views
prevent single quotes in bash script
I have a bash script that's just a shortcut to the grep command. I call it like this:
stx -p /var/www -t 'my text'
This would run this command:
sudo grep -rinI /var/www -e 'my text'
I'm trying to ...
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
1
answer
325
views
grep not working when I enclose the directory in double quotes
When I do something like this:
grep "hello" /home/paul/*
It works.
But when I do something like this:
grep "hello" "/home/paul/*"
grep display the error:
grep: /home/paul/*: No such file or ...
-2
votes
2
answers
3k
views
Grep not working with variables, even with quotes
name=$(echo "$FILENAME" | grep -E '*\.(eng|por|pt-BR)\.*')
Why this line doesn't work?
if I do
echo "Test (2013).1080p.por.mkv" | grep -E "*\.(eng|por)\.*"
It works, I tried with "" without " and ...
4
votes
4
answers
5k
views
How do I invoke jq inside awk?
Essentially I have a file.log as follow
blah blah
blah blah
Hello world | {"foo": "bar"}
blah blah
Hello earth | {"foo1": "bar1"}
Now my goal is to write some shell commands to have desire output ...
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 ...
4
votes
3
answers
13k
views
Escape [ in grep
I read strings from stdin and I want to display the users that match the strings. Problem is, if the user inputs the character '[', or a string containing it.
grep -F does not work because the line ...
5
votes
4
answers
10k
views
Backslash usage in different commands
I have been trying to get a better understanding of how backslash is used in certain commands. I understand its usage for escaping special characters (Such as echo 'that'\''s no moon'
), but the ...
1
vote
3
answers
945
views
Why doesn't grep return what I expect when I use single quotes
I have a file with the below contents:
sh-4.2$ cat file1
example of multiple
pattern
this is an
example of multipole
sorry multiple
pattern matching
using grep
so the example is the
file itself
-...
0
votes
4
answers
2k
views
grep syntax for searching strings with single-quotes?
So, I have a .js file as below and I am trying to search with the below grep pattern. I am not sure what mistake I did but it does not give any output even though the file has that pattern. What ...
-1
votes
1
answer
904
views
How to grep and treat meta character as normal character? [closed]
I am trying to recursively find some pattern which contains meta character.
Pattern that I searching for is template <int N>
I have tried :
grep -F -lir "template <int N>" * # ...
7
votes
1
answer
1k
views
How to extract the string between two \n in a file
I have a file with pattern
<span class="WebRupee">Rs.</span>\n29\n<br/><font style="font-size:smaller;font-weight:normal">\n3 days\n</font></td>, <td class=...
8
votes
5
answers
33k
views
How to find lines that begin with **
I need to find if any lines in a file begin with ** .
I cannot figure out how to do it because * is interpreted as a wildcard by the shell.
grep -i "^2" test.out
works if the line begins with a 2 ...
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?
1
vote
1
answer
15k
views
grep with variable in a variable
I want to filter the svlog file by date and split the result by the space,
so when i enter the date, it didn't work for me,
please refer to the script that I wrote below, the problem was in this ...
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 ...
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 ...
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 ...
1
vote
1
answer
8k
views
Passing a variable argument to egrep in a bash script
I have a script, myScript, which is trying to egrep the script argument in a file. Somehow variable expansion isn't working properly with the egrep command. I believe I've isolated the problem ...
2
votes
1
answer
1k
views
bash regex: asterisk gives ambiguous search results with grep
I am using a simple text file to test the * meta-character through grep.
The text file is as below:
1
11
111
1111
11111
111111
d
da
daa
daaa
b
bc
bcc
bccc
Now when I search digit 1 using grep like ...
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 ...
2
votes
1
answer
249
views
In bash, grep for a line beginning with \, and assign the result using backticks
In bash, I'm trying to grep a file for a line beginning with a \, and return the result using backticks.
For example:
echo \\Hello > myFile
out=`cat myFile | grep '^\\Hello'`
echo $out
returns ...
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 ...
2
votes
3
answers
352
views
grep .* returns results from .bash_history and complains about
I'm new to Linux and so far I've been playing around with some utilities, specifically the grep utility. I decided to create a new file (aptly called 'newfile') with the following content:
Lady of ...
15
votes
2
answers
18k
views
How to use multiline as group-separator in grep?
In grep you can use --group-separator to write something in between group matches.
This comes handy to make it clear what blocks do we have, especially when using -C X option to get context lines.
$ ...
2
votes
1
answer
950
views
grep misreads pattern from variable
I have a problem with escaped pattern put in grep.
My test file is:
export_cc = ${dir}/aaa/bbb/ccc
export_cc = ${dir}/aaa/bbb/eee
export_cc = ${dir}/aaa/bbb/ddd
export_cc = ${dir}/aaa/bbb/fff
...
3
votes
4
answers
20k
views
Wildcards for filepaths aren't working in grep [duplicate]
I need to grep words like these:
ABC-DEF
AB2-DEF
AB3-DEF
AB-DEF
So I was trying:
grep AB*-DEF
grep -w -AB*-DEF
grep -w AB*DEF
But neither of them are working.
2
votes
1
answer
14k
views
grep: Syntax error near unexpected token `('
I have this problem: I'm looking for a string inside file .
Syntax is:
grep -E ‘( ^ | [[:space:]] )[A-Z]{2}[[:digit:]]{2}((- | [[:space:]] )[[:alnum:]]{4}) {3} ’ (filename)
When I run this ...
9
votes
4
answers
41k
views
How do I perform xargs grep on grep output that has spaces?
I'm searching for files based on a regular expression, and then I'm trying to search those files for content. So, for example, I have something like
#Find all C++ files that match a certain pattern ...
1
vote
2
answers
955
views
How to put $@ in quotes?
My bash script looks like this:
#!/bin/bash
grep -r --color=always $@ . | nolong
The file is saved in /usr/bin/findstr
Everything's ok when I run this:
findstr hello
But when I run this:
findstr ...
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(...
3
votes
2
answers
1k
views
Why does "grep '.*[s]' file" work and "grep .*[s] file" doesn't?
Comparing
grep '.*[s]' file
with
grep .*[s] file
Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.
4
votes
4
answers
2k
views
fgrep beginning of line?
I'd like to use fgrep to handle searching literal words with periods and other meta-characters in grep, but I need to ensure the word is at the beginning of the line.
For example, fgrep 'miss.' will ...
2
votes
1
answer
662
views
Help with using quotes in grep searches
I have a file with variables in it of the form a(i)%b(j)%c where the a, b, and c are always the same, but the indices i and j may be different (including multiple characters). So I've played around ...
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'...
0
votes
1
answer
147
views
Quote escaping struggle with grep and sed
I'm writing a bash script to extract data from html tags and I found this command in another thread : grep -o '<tr>.*</tr>' HTMLFILE | sed 's/\(<tr>\|<\/tr>\)//g' > NEWFILE, ...
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 ...
0
votes
3
answers
568
views
How do I match a string with symbols in a grep-kind of way? [duplicate]
I have a file with this contents (or similar):
# cat /var/www/htpasswd
foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/
and I'm trying to verify the presence of an entry in it, by matching it, like this:
#...
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 ...
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 ...
4
votes
4
answers
2k
views
How can I grep for a string containing regex metacharacters like $ and '?
I want to search all files in the current directory and below for the substring $form['#node']. So, I have tried, initially:
grep -R "\$form\[\\\\'" . and grep -R "\$form\[\'" .
But it returns no ...
1
vote
1
answer
1k
views
How to grep including single quote in a file
I have this line from file.php:
'user' => '',
What would be the appropriate command using grep to query the exact line?
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 ...