Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

6 votes
1 answers
1128 views
How does pattern matching work in grep for accented characters (eg. á, è, ò)
What characters match the following regex : ``` ^[a-zA-Z]$ ``` Specifically, should characters with accents (eg. á, è, ò) match this regex? Or just 26 lower and upper case alphabets? I have tried to [check this](https://regex101.com/r/KN4fgg/1) in an online regex, and accented charact...
What characters match the following regex :
^[a-zA-Z]$
Specifically, should characters with accents (eg. á, è, ò) match this regex? Or just 26 lower and upper case alphabets? I have tried to [check this](https://regex101.com/r/KN4fgg/1) in an online regex, and accented characters did not match. When I tried it out with grep on my Linux (Ubuntu) machine it **did match** the accented characters. While rg(ripgrep) **did not match** it. enter image description here I can match accented characters with rg using [A-zÀ-ÿ] But is there a way to exclude accented characters from matching in grep? PS: [This](https://unix.stackexchange.com/questions/505477/grep-to-find-a-word-matching-a-specific-pattern-and-ignore-accents) question talks about how accented chars can be included, not excluded.
adiSuper94 (61 rep)
Jul 3, 2022, 02:07 AM • Last activity: Aug 20, 2024, 01:19 PM
0 votes
1 answers
459 views
using ripgrep with regex including literal dollar symbol
Suppose I have a script containing something like VAR=${VAR1%.*} I'm looking for a command along the lines of rg "${.*%" to find it, but I can't get anywhere near. all of these fail rg "\$\{.\*%" rg \$\{.\*% rg "\$\{.*%" rg \$\{.*%
Suppose I have a script containing something like VAR=${VAR1%.*} I'm looking for a command along the lines of rg "${.*%" to find it, but I can't get anywhere near. all of these fail rg "\$\{.\*%" rg \$\{.\*% rg "\$\{.*%" rg \$\{.*%
njamescouk (3 rep)
Mar 26, 2024, 07:55 AM • Last activity: Mar 26, 2024, 08:33 AM
1 votes
2 answers
1882 views
How to individually process each path from a list of paths output from ripgrep
I'm on Linux Ubuntu 18.04 and 20.04. Ripgrep (`rg`) can output a list of paths to files containing matches like this: ```bash # search only .txt files rg 'my pattern to match' -g '*.txt' -l # long form rg 'my pattern to match' --glob '*.txt' --files-with-matches ``` Output will be: > path/to/file1.t...
I'm on Linux Ubuntu 18.04 and 20.04. Ripgrep (rg) can output a list of paths to files containing matches like this:
# search only .txt files
rg 'my pattern to match' -g '*.txt' -l
# long form
rg 'my pattern to match' --glob '*.txt' --files-with-matches
Output will be: > path/to/file1.txt > path/to/file2.txt > path/to/file3.txt etc. I'd like to then run another command on each path, such as tree $(dirname $PATH), to get a list of all files in the directory containing the matching file. How can I do that? I feel like xargs might be part of the answer maybe? But piping to xargs like this as a start seems to only handle the last-printed file:
rg 'my pattern to match' -g '*.txt' -l | xargs -0 -I {} dirname {}
Note: if you can demo with grep too that might be useful too for those without ripgrep, albeit ripgrep is super easy to install . ## References: 1. https://unix.stackexchange.com/questions/453183/ripgrep-print-only-filenames-matching-pattern/453188#453188
Gabriel Staples (2972 rep)
Dec 3, 2021, 06:15 AM • Last activity: Jul 26, 2023, 06:34 PM
2 votes
1 answers
217 views
to search for files with 2 (full or partial) keywords content (txt files) in a folder and sub folder and files with specific filename
I just want to share this, and hoping will get more similar tool. I got a directory of text files.. i need to search for the files with 2 (partial) words in it.. the keywords are in random order, but on a same line. So far, i can use this: $ rg -i '\w*keyword1\w*.*\w*keyword2\w*|\w*keyword2\w*.*\w*k...
I just want to share this, and hoping will get more similar tool. I got a directory of text files.. i need to search for the files with 2 (partial) words in it.. the keywords are in random order, but on a same line. So far, i can use this: $ rg -i '\w*keyword1\w*.*\w*keyword2\w*|\w*keyword2\w*.*\w*keyword1\w*' --glob '*.txt' --line-number -l /path/to/search $ rg -g '*.txt' -l -i 'keyword1.*keyword2|keyword2.*keyword1' /path/to/search Both of these can do the same job. Anybody have other that can do the same job ? Pls do share. I found myself need this quite often to locate the proper file.. However i don't know how to search file that filename is 2 keywords that are not in order. How about searching for filename with 2 keyword that is not in order ? Example: weirdfilename_key1Nkey3Nkey2etc.txt search among huge database for file with which name only remember consist of "key2" and "key3" in it, but not sure the order..
andrew_ysk (155 rep)
Apr 9, 2023, 11:00 PM • Last activity: Apr 10, 2023, 07:14 AM
0 votes
2 answers
37 views
List files where searched term occurs more than a Threshold
I have a command like rga --files-with-matches --count-matches --sort path -i -e "use cases?" -e "user stor(y|ies)" -e "Technical debt" -e "Code Quality" -e "software development" -e "Agile Manifesto" The output is like a1.pdf:18 a2.pdf:10 a3.pdf:14 .... Here, `:NUM` is number of matches. I want all...
I have a command like rga --files-with-matches --count-matches --sort path -i -e "use cases?" -e "user stor(y|ies)" -e "Technical debt" -e "Code Quality" -e "software development" -e "Agile Manifesto" The output is like a1.pdf:18 a2.pdf:10 a3.pdf:14 .... Here, :NUM is number of matches. I want all files who have more than 10 matches (without the colon and number, so that I can pipe the output to another command). Like: a1.pdf a3.pdf .... I tried .. | cut -d':' -f2 but it only give the number. .. | cut -d':' -f1 only gives the file name. What might be the solution here?
Ahmad Ismail (2998 rep)
Mar 3, 2023, 01:01 AM • Last activity: Mar 3, 2023, 02:19 AM
7 votes
3 answers
3067 views
How to match a literal string containing an unclosed quote with ripgrep?
I have a file that contains the some python code. There is a line that contains the following(including the quotes) `'hello "value"'` I want to search `'hello "value"` in the file. Notice the unclosed quote. I'm using ripgrep with the folowing command: `rg -F 'hello "value"` The above command is not...
I have a file that contains the some python code. There is a line that contains the following(including the quotes) 'hello "value"' I want to search 'hello "value" in the file. Notice the unclosed quote. I'm using ripgrep with the folowing command: rg -F 'hello "value" The above command is not working for the input 'hello "value" in bash/ zsh. All i want is the literal match. I have used the flag F but because of unclosed quotes in the input string it is not working at all. I also tried enclosing the input inside single/ double quotes as so: rg -F "'hello "value"" or rg -F ''hello "value"' The above is not working as well. I thought the F flag would tell ripgrep to consider the input literally as it is? How do I fix this?
Haris Muzaffar (249 rep)
May 20, 2021, 03:13 PM • Last activity: Nov 7, 2022, 04:00 PM
2 votes
2 answers
2777 views
How can I search only git tracked files with a specific file extension?
I'd like to search all git tracked files that 1. has an `.hs` file extension and 2. contain the word `import` in any lines. I've tried to use `git ls-files -z | xargs -0 rg -g '*.hs' "import"` however unfortunately if you pass an explicit list of files to `rg` it seems to ignore the `-g` glob flag....
I'd like to search all git tracked files that 1. has an .hs file extension and 2. contain the word import in any lines. I've tried to use git ls-files -z | xargs -0 rg -g '*.hs' "import" however unfortunately if you pass an explicit list of files to rg it seems to ignore the -g glob flag. I could potentially use grep to use some regex lookbehind to extract files with a specific file extension, or potentially filter the output from git ls-files -z (ensuring we keep the null separated filenames aspect, both approaches seem a bit clunky though... If anyone has any ideas.
Chris Stryczynski (6603 rep)
Jul 21, 2022, 06:12 PM • Last activity: Jul 21, 2022, 06:23 PM
1 votes
1 answers
173 views
How to use stdin to give data to rankmirrors command
Probably a rooky question, but I have seen that the "rankmirrors" command can use the **stdin** input. But when I run the following command (which retrieve all URL in use in the "mirrorslist" file to the "rankmirrors"), I get an error: ``` Bash $ rg -e "^Server" /etc/pacman.d/mirrorlist | rg -oe "ht...
Probably a rooky question, but I have seen that the "rankmirrors" command can use the **stdin** input. But when I run the following command (which retrieve all URL in use in the "mirrorslist" file to the "rankmirrors"), I get an error:
Bash
$ rg -e "^Server" /etc/pacman.d/mirrorlist | rg -oe "https.*"  | rankmirrors -t
Must specify URL, mirrorfile, or stdin.
There is another way to use the previous command **stdout** as current **stdin** of the command ?
Apitronix (113 rep)
Mar 19, 2022, 08:29 AM • Last activity: Mar 19, 2022, 10:28 AM
3 votes
5 answers
2317 views
Recursive grep matching only specific line number
How can I can I find files that contain a specific pattern **on a specific line number** ? Let's assume I have a directory with a bunch of text files containing 3 lines, such as: ``` Title A Category X Description Y ``` How can I grep / filter every files that have `Category X` on line `2`? How can...
How can I can I find files that contain a specific pattern **on a specific line number** ? Let's assume I have a directory with a bunch of text files containing 3 lines, such as:
Title A
Category X
Description Y
How can I grep / filter every files that have Category X on line 2? How can I find files that have Title A as line 1? I looked at the grep man page, ripgrep and alternative but not sure you can limit the search of a pattern to specific line numbers.
Pierre-Jean (2279 rep)
Feb 13, 2022, 05:22 PM • Last activity: Feb 20, 2022, 02:07 PM
1 votes
2 answers
833 views
using ripgrep to find adjacent word
How to use ripgrep to find adjacent duplicated words. for example one hello hello world How to locate `hello hello` by using ripgrep? Solved ---- rg '(hello)[[:blank:]]+\1' --pcre2 <<<'one hello hello world'
How to use ripgrep to find adjacent duplicated words. for example one hello hello world How to locate hello hello by using ripgrep? Solved ---- rg '(hello)[[:blank:]]+\1' --pcre2 <<<'one hello hello world'
jian (597 rep)
Feb 2, 2022, 04:33 PM • Last activity: Feb 2, 2022, 08:51 PM
78 votes
1 answers
58492 views
ripgrep: print only filenames matching pattern
Using [ripgrep (`rg`)](https://github.com/BurntSushi/ripgrep), can I print only the filenames which match a given pattern? There are two separate things I'm trying to do: 1. Match the pattern to the pathname itself (like `ag -g pattern`) 1. Match the pattern to the contents of the file and print onl...
Using [ripgrep (rg)](https://github.com/BurntSushi/ripgrep) , can I print only the filenames which match a given pattern? There are two separate things I'm trying to do: 1. Match the pattern to the pathname itself (like ag -g pattern) 1. Match the pattern to the contents of the file and print only the filename I can't work out how to do either one.
Tom Hale (32922 rep)
Jul 3, 2018, 09:25 AM • Last activity: Dec 3, 2021, 10:10 AM
1 votes
1 answers
1364 views
How to I properly set the advanced FZF_DEFAULT_COMMAND environment variable to get it working properly with ohmyz.sh with fzf plugin installed?
I'm new to z shell and ohmyz.sh. I have the following in my zshrc to integrate fzf with rg. This is exactly how it appears in the fzf readme: ``` FZF_BASE=/usr/local/bin DISABLE_FZF_AUTO_COMPLETION="true" DISABLE_FZF_KEY_BINDINGS="true" INITIAL_QUERY="" RG_PREFIX="rg --column --line-number --no-head...
I'm new to z shell and ohmyz.sh. I have the following in my zshrc to integrate fzf with rg. This is exactly how it appears in the fzf readme:
FZF_BASE=/usr/local/bin
DISABLE_FZF_AUTO_COMPLETION="true"
DISABLE_FZF_KEY_BINDINGS="true"
INITIAL_QUERY=""
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
  fzf --bind "change:reload:$RG_PREFIX {q} || true" \
      --ansi --disabled --query "$INITIAL_QUERY" \
      --height=50% --layout=reverse
It kind of works but I'm seeing some weird and broken behavior: 1. The weird behavior is that when I reload zshell, fzf fires up immediately without me hitting a key or typing in the command. It works perfectly, otherwise, though. 2. The broken behavior is that when I manually type in fzf, the search is initiated but FZF_DEFAULT_COMMAND is set to what the plugin uses. I tried fixing this behavior by slapping export in front of FZF_DEFAULT_COMMAND but then when I reload zsh, I get an error: /Users/me/.zshrc:export:313: not valid in this context: --bind Next I turned the ohmyzsh plugin off and modified my code to this:
FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
  fzf --bind "change:reload:$RG_PREFIX {q} || true" \
      --ansi --disabled --query "$INITIAL_QUERY" \
      --height=50% --layout=reverse
export FZF_DEFAULT_COMMAND
This kind of works, but again, it fires up fzf as soon as I load zsh. And the formatting of the search is mangled and ugly with ansi characters.
StevieD (1123 rep)
Aug 29, 2021, 06:21 PM • Last activity: Aug 30, 2021, 03:42 PM
13 votes
2 answers
6895 views
ripgrep path pattern
I'd like ripgrep to search paths with the specified pattern. For e.g. ``` rg PATTERN --path REGEX ``` where PATTERN is the pattern to grep and REGEX is the path matching pattern. I have scattered through the documentation and I am unsure if this functionality is baked in.
I'd like ripgrep to search paths with the specified pattern. For e.g.
rg PATTERN --path REGEX
where PATTERN is the pattern to grep and REGEX is the path matching pattern. I have scattered through the documentation and I am unsure if this functionality is baked in.
p0lAris (233 rep)
Feb 26, 2019, 04:41 PM • Last activity: Jan 15, 2021, 01:04 PM
1 votes
4 answers
73 views
Replace (one or) two different patterns in a file with regexp
Suppose an `input.txt` file that contains several strings as the following ones: [[foo>a|a]] [[foo>b|b]] [[foo>c|c]] that I'd like to replace by: :foo:`a` :foo:`b` :foo:`c` I guess I could manage to achieve this result with `sed` or `rg` (I never used `awk`). But this file also contains other string...
Suppose an input.txt file that contains several strings as the following ones: [[foo>a|a]] [[foo>b|b]] [[foo>c|c]] that I'd like to replace by: :foo:a :foo:b :foo:c I guess I could manage to achieve this result with sed or rg (I never used awk). But this file also contains other strings as the following ones: [[foo>a|d]] [[foo>b|e]] [[foo>c|f]] that I'd like to replace by: :foo:d :foo:e :foo:f All my attempts failed because I don't see how to handle two different patterns at once. Do you know some ways to achieve the latter result (and, BTW, the former)?
Denis Bitouz&#233; (298 rep)
Dec 3, 2020, 03:12 PM • Last activity: Dec 3, 2020, 04:50 PM
0 votes
2 answers
129 views
ripgrep type definition to skip tests
I would like to be able to run `rg -Ttests` instead of typing `rg -g'!tests/' -g '!test/' -g'!Tests/' -g '!Test/'` , is that possible?
I would like to be able to run rg -Ttests instead of typing rg -g'!tests/' -g '!test/' -g'!Tests/' -g '!Test/' , is that possible?
chx (880 rep)
Sep 11, 2019, 02:58 AM • Last activity: Sep 11, 2019, 01:52 PM
18 votes
1 answers
12350 views
How is ripgrep different from silver searcher ag?
Are these related? Which is faster? Can either be limited to directory-names? https://github.com/BurntSushi/ripgrep https://github.com/ggreer/the_silver_searcher
Are these related? Which is faster? Can either be limited to directory-names? https://github.com/BurntSushi/ripgrep https://github.com/ggreer/the_silver_searcher
johny why (371 rep)
Aug 24, 2018, 09:47 PM • Last activity: Jun 10, 2019, 09:16 PM
35 votes
1 answers
22517 views
How can I search a specific list of files with ripgrep?
I've got a list of files that I would like to search for a pattern with ripgrep. How can this be done?
I've got a list of files that I would like to search for a pattern with ripgrep. How can this be done?
Chris Stryczynski (6603 rep)
Jan 15, 2019, 12:32 PM • Last activity: Jan 15, 2019, 09:44 PM
Showing page 1 of 17 total questions