Skip to main content
Unix & Linux

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.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
128 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
508 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
585 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 "...
3 votes
1 answer
354 views

How to do non-greedy multiline capture with recent versions of pcre2grep?

I noticed a difference in behavior between an older pcre2grep version (10.22) and a more recent one (10.42), and I am wondering how I can get the old behavior back. Take the following file: aaa bbb ...
0 votes
1 answer
756 views

grep behaviour is different when run using bash -c '...'

I met an interesting issue while working with this code from Stack Overflow: tripleee's answer on "How to check if a file contains only zeros in a Linux shell?" Why does the same bash code ...
1 vote
2 answers
111 views

How to extract a sub-heading as string which is above a search for word

I'm new to Bash and I've been self-taught. I think I'm learning well, but I do have staggering gaps in my base knowledge. So sorry if this is woefully simple bbuuuttt... Essentially, I need to sift ...
TC575's user avatar
  • 13
4 votes
1 answer
382 views

Is there a way to set up default values for grep options such as `--exclude-dir`?

I often have to use the --exclude-dir to exclude various folders such as .git from the search path. grep -r --exclude-dir=.git --exclude-dir=another_path XXX Then, the command line becomes quite ...
tinlyx's user avatar
  • 1,086
0 votes
0 answers
26 views

How can I grep the output of ffprobe? [duplicate]

I'd like to only see those lines containing "Stream #" from an ffprobe output. But whatever I do, it continues to show the whole output. Neither "|" nor ">" pipes work....
0 votes
1 answer
112 views

How to match exact string? [duplicate]

I tried this grep -rn "application_config_project" . I got many application_config_project_name = f"{app_acronym}-application-config" github_application_config_repo = ...
MJoao's user avatar
  • 47
2 votes
1 answer
78 views

Redirect `rtf` output to file

System Info alinuxchap@libertus-desktop:/usr/share/X11/xkb $ uname -a Linux libertus-desktop 6.12.25+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.25-1+rpt1 (2025年04月30日) aarch64 GNU/Linux alinuxchap@...
3 votes
2 answers
328 views

Programs to visually verify the placement of null bytes by grep [duplicate]

I have been using the grep command with --null. grep --null -r -n -- "$pstr" "$pdir" The man page for my version of grep (on Mac OS Sequoia) says: --null Prints a zero-byte ...
0 votes
1 answer
123 views

grep command not finding text in MS-Office or PDF documents

Debian GNU/Linux 11 (bullseye), grep (GNU grep) 3.6 I need find string in current directory within all files (doc, docx and pdf), grep command not working for me: grep -ril "word" . It ...
minto's user avatar
  • 575
2 votes
4 answers
164 views

Grep (BRE) on surrounding delimiters w/o consuming the delimiter? Counting delimiter-separated strings between filename and extension

I have a dataset of images labeled/classified by characteristics, where an image can have more than one label. I want to count how many of each identifier I have. A toy dataset is created below, with ...
6 votes
2 answers
480 views

Can I use grep or strings to find the previous atime of a file still present on my btrfs?

The metadata of this file which resides on my HDD is written by CoW, therefore can I look for it just by using grep or strings, and the filename?
5 votes
3 answers
511 views

Can grep output the complete input verbatim only if there was a match?

I'm processing input data in a pipeline consisting of several programs. In one step of the pipeline, I want to know if there are certain lines in the input, but I want to output everything as-is ...

15 30 50 per page
1
2 3 4 5
...
341

AltStyle によって変換されたページ (->オリジナル) /