Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
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 ...
user2551229's user avatar
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.
GP92's user avatar
  • 825
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 ...
fergiu's user avatar
  • 23
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 ...
quanticle's user avatar
  • 500
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 ...
KEKC_leader's user avatar
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
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.
JHK's user avatar
  • 205
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 ...
Yimin Rong's user avatar
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 ...
John S.'s user avatar
  • 21
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'...
lkisac's user avatar
  • 259
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, ...
Zil0's user avatar
  • 25
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 ...
Brad Harris's user avatar
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 ...
Registered User's user avatar
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: #...
Pablo Fernandez's user avatar
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 ...
Philippe Blayo's user avatar

15 30 50 per page