Questions tagged [grep]
For questions pertaining to grep, a command-line tool for searching text patterns in files. Use this tag for questions about grep itself or questions about issues arising from using the grep command-line tool.
5,117 questions
0 votes
0 answers
10 views
Find document containing specific strings among all completed jobs in CUPS 2.4.2
Linux Debian. Some time ago I created Libreoffice Writer document and printed it, but didn't save it. I want to find it electronic copy. How to find a document containing specific strings (in body ...
0 votes
4 answers
108 views
How to grep man output by flag name
I created a file man df &> man_df Then I want to fetch information about flag -x from the file Expected result is "-x, --exclude-type=TYPE" But command grep "-x" man_df is ...
1 vote
6 answers
143 views
Cutting a certain substring from a "grep'ed" result
I need to isolate a certain substring from a grep command. A typical line inside $FILE would look like this: random text [random number]FIXEDTEXT more random text. I need to retrieve the random ...
3 votes
3 answers
921 views
How do I ensure a bash script argument is a specific value?
The following script is supposed to check $1 and see if it is a specific value. It only works when one Bash [[... =~ ...]] regex check is passed in an if statement. The error is: When more than one ...
8 votes
1 answer
1k views
How and why does grep match this pattern (containing newline)?
Consider this scenario: $ x='yyy ' $ printf %s "$x" | od -tc 0000000 y y y \n 0000004 $ printf %s "xxx" | od -c 0000000 x x x 0000003 $ printf %s "xxx" | ...
1 vote
3 answers
169 views
find awk grep - search and replace & passing modified contents to awk to overwrite the existing file
I have a folder with many subfolders full of various Quarto(reg) files & in those files there are links that are located in varying positions in the file lines. UPDATE ON 3 November 2025 in ...
7 votes
9 answers
745 views
How to get every lines between nth and (n+1)th match of grep in text file
I've got a text file containing e.g. Success Something Anything Success Somebody Anybody Someone Success (line 8 is deliberately an empty line) and I would like to export every line between the nth ...
2 votes
5 answers
893 views
How to use a "grep" result as an input of another grep, resulting in multiple lines?
I have built a Visual Studio solution, containing 92 projects. While building them, I get the following line for every one of them: 10>------ Rebuild All started: Project: HostLinkSw, Configuration:...
0 votes
3 answers
182 views
How to construct a command from the output of another command?
I'm working with a Linux application. There is a command that I run to display a set of parameters. I would like to run the command and then grep through the results of the command and build a ...
10 votes
5 answers
637 views
Grep with output of not the complete line
With grep I can filter lines. But if the lines are pretty long it gets messy. How can I only get "some chars around" my search-string? f.txt this is a red cat in the room this is a blue ...
3 votes
2 answers
161 views
Bug or not?: grep stops finding more matches after "Binary file ... matches"
I have a longer log file, and I wanted to extract the lines that match a specific word using grep. However after a few thousand lines with matches, grep output Binary file ... matches and that was ...
-1 votes
1 answer
87 views
How do I grep for "-d"? [duplicate]
I'm trying to search a directory of files for occurences of the literal string -d /data/. When I try using grep, I get an error due to the fact that -d is a grep flag: $ grep -F "-d /data" ...
-2 votes
1 answer
170 views
sed inplace in selective block
I have a dir containing logstash config files these files have filter blocks, and sometimes nested child blocks need to match whole filter block filter { any text till final matching closing brace for ...
4 votes
3 answers
549 views
In Grep, how can I `grep -r --exclude build/lib/**/*.py`
I setup a directory structure as follows: mkdir -p /tmp/test/build/lib/aaa/ cd /tmp/test mkdir rar echo "Hello" > foo.py echo "Hello" > bar.py echo "Hello" > ...
8 votes
1 answer
618 views
Is there any way to see the string that was matched in grep?
I'm not talking about -o option. Posix says: The search for a matching sequence starts at the beginning of a string and stops when the first sequence matching the expression is found, where "...