A list of puns related to "Grep"
Sorry for this trivial question, but I’m learning much about grep currently and I have some questions overflowing that I should get off my mind.
grep -l str * executes grep on all files in the current directory, including directories.
What are some good ways to have it skip directories, since it can’t operate on them and returns an error for them?
Preferably with just Bash operators similar to Zsh’s glob operator: *(.).
Thanks very much
Has anyone figured out how to get the live_grep
function of telescope.nvim to behave similarly to :Ag
from fzf.vim?
I already have nvim-telescope/telescope-fzf-native.nvim
installed and fzf works fine for find_files
& grep_string
(too slow compared to live_grep
). But for some reason, this doesn't apply for live_grep
.
If anyone has any ideas, this would be a huge gamechanger since it's pretty much the only thing keeping fzf.vim in my plugins. Thanks!!
I’m working on a book where the person before me was using manual hyphens to break up a word so the sentence fit better on the line. I’m looking for a GREP search to find all hyphens at the end of a line. When I search for just a hyphen it’s showing ALL the hyphenated words like dates and names.
I am trying the following:
grep -r function_name[^;]*{
it keeps matching the function calls though like this:
function_name();
why is it matching lines without the curly brace?
how should I modify this to match declarations that spans multiple lines?
Please let me know if my question is not clear.
Hi, I have a list of hundreds of lines, and each line has keywords. I'm actually using this function to match 1 or 2 words that will show two groups of lines for each of the two words:
case $2 in
*) for var in $2;
do grep -i -E $2 /file.txt
done
esac
But I want to write "foo bar" and read all the lines containing both "foo" and "bar", I've tried to do so:
case "$2 $3" in
*) for var in "($2 $3)";
do grep -i -E "($2 $3)" /file.txt
done
esac
I get an endless output of lines containing also the word " " (ie "space"). I'm several hours I'm trying to solve this issue, also using "cat", "awk" or other commands, without success.
Can you help me please?
How can I easily find all lines containing one string followed by another line containing another string? I can use fugitives `:Ggrep` to do this for single lines and get the result into the quickfix list, but how do I do it for the multiline case?
It would be awesome if there existed a command that was as convenient as this fictional example: `:Ggrepmulti "A" "B"`
Your server is now running two services: the sshd (Secure Shell Daemon) service that you use to login; and the Apache2 web server. Both of these services are generating logs as you and others access your server - and these are text files which we can analyse using some simple tools.
Plain text files are a key part of "the Unix way" and there are many small "tools" to allow you to easily edit, sort, search and otherwise manipulate them. Today we’ll use grep
, cat
, more
, less
, cut
, awk
and tail
to slice and dice your logs.
The grep
command is famous for being extremely powerful and handy, but also because its "nerdy" name is typical of Unix/Linux conventions.
cat
like this: cat /var/log/apache2/access.log
less
to open the same file, like this: less /var/log/apache2/access.log
- and move up and down through the file with your arrow keys, then use “q” to quit.less
, look at a file, but practice confidently moving around using gg, GG and /, n and N (to go to the top of the file, bottom of the file, to search for something and to hop to the next "hit" or back to the previous one)sudo
usage by viewing /var/log/auth.log
with less
tail /var/log/apache2/access.log
(yes, there's also a head
command!)tail -f /var/log/apache2/access.log
(while accessing your server’s web page in a browser)|
(pipe) symbolcat
, but pipe that output to grep
with a search term - like this: cat /var/log/auth.log | grep "authenticating"
grep "authenticating" /var/log/auth.log
grep "authenticating" /var/log/auth.log | grep "root"
cut
command to select out most interesting portions of each line by specifying "-d" (delimiter) and "-f" (field) - like: grep "authenticating" /var/log/auth.log| grep "root"| cut -f 10- -d" "
(field 10 onwards, where the delimiter between field is the " " character). This approach can be very useful in extracting useful information from logEvery now and again I have to kill a misbehaving app. How can I do so with one command?
I have file1.txt
:
cat file1.txt
red 1
red 2
1
and file2.txt
:
cat file2.txt
red 3
red 4
4
I'm looking to find all txt files that contains either red 1 or red 4. This is what I tried but don't get the expected result:
find . -name '*.txt' -exec grep -q red {} \; -exec grep -E '1|4' {} \;
red 4
4
red 1
1
It looks like it is the same as doing the second grep only i.e.
find . -name '*.txt' -exec grep -E '1|4' {} \;
red 4
4
red 1
1
What am I missing?
I can confirm that “grep -l -d skip word *” returns a list of files in my local directory (skipping subdirectories) which contain the string “word” in them.
However, I called this from subprocess in the following way:
>>> import subprocess; subprocess.run(args=[“grep”, “-ld”, “skip”, “a”, “*”])
and received the error “*: No such file or directory”.
It works if I pass the string as a single string with the option shell=True.
Is there something wrong with how the * operator is being passed?
Thank you
I stumbled on a certain feature some time ago, and completely forgot where I found it.
But I remember what it does:
Anyone kind enough to point out a package that does this or something close to it?
template here,
errors:
=> grapejuice-4.8.2_1: running pre-pkg hook: 03-rewrite-python-shebang ...
=> ERROR: grapejuice-4.8.2_1: pre-pkg_03-rewrite-python-shebang: 'grep -o '[[:digit:]]\.[[:digit:]]\+$'' exited with 1
=> ERROR: in hook() at common/hooks/pre-pkg/03-rewrite-python-shebang.sh:8
=> ERROR: in run_func() at common/xbps-src/shutils/common.sh:21
=> ERROR: in run_pkg_hooks() at common/xbps-src/shutils/common.sh:245
=> ERROR: in main() at common/xbps-src/libexec/xbps-src-prepkg.sh:47
=> ERROR: grapejuice-4.8.2_1: pre-pkg_03-rewrite-python-shebang: 'pyver="$(find ${PKGDESTDIR}/usr/lib/python* -prune -type d | grep -o '[[:digit:]]\.[[:digit:]]\+$')"' exited with 1
=> ERROR: in hook() at common/hooks/pre-pkg/03-rewrite-python-shebang.sh:8
=> ERROR: in run_func() at common/xbps-src/shutils/common.sh:21
=> ERROR: in run_pkg_hooks() at common/xbps-src/shutils/common.sh:245
=> ERROR: in main() at common/xbps-src/libexec/xbps-src-prepkg.sh:47
yes my template is absolutely shit. i don't know what i'm doing and i'm just copying the AUR PKGBUILD, please criticize
Hey,
currently when working on a large codebase containing multiple repositories I use :cd
to set the directory for finding files/grepping. This drastically reduces the search space, but isn't a very good flow when having to :cd
between 6 or 7 different directories often.
I'm looking for a way to specify a list of directories on which grep and file find will be applied. The use case for this is similar to the don't grep/find stuff defined in .gitignore
, just usable with codebases containing multiple git repos.
There are two merged telescope PRs somewhat touching the subject:
For fzf there is a workaround to specify the dirs in an ENV variable.
UPDATE
Looking at telescope help (:h telescope
) it shows that both find_files
and live_grep
both have search_dirs
as an argument. Need to do a PoC with this. Am lacking Lua knowledge to pass a list of dirs to the function call from nvim.
Attempt
:lua require("telescope.builtin").find_files( <List of dirs> )
Does anyone know a flow which would cover this?
Is there a grep to find and change after a number imput a force line break?
I have some like this
"1651651 John Doe"
The number is variable , and the name too.
I want to do that
"1651651
John Doe"
GNU grepのWindows64bitネィティブ版は、コマンドラインのワイルドカードを展開しない問題があってリビルドしないといけない。
--修正の手順は以下の通り--
提供されているpatchファイルはインクルードパスをフルパスで書いてある場所があり(⌒_⌒; )、 事前に自前環境に合わせて直すか、 またはビルドの過程でパスを変換するスクリプトを通す手当が必要になる。
例(patchの中身):
+# include "E:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.30.30705\include\limits.h"
+#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\ucrt\ctype.h"
patchはLinux上で当てる。 ソースツリーのファイルの中身には英語でも日本語でもない文字が含まれているので、 Windows版のツールが正常に動作するかどうかあやしい。
まず、grep-3.7.tar.xzを展開してから そのツリーのトップ(READMEなどがある場所)へpatchファイルを入れて実行する。
$ patch -Np1 -i grep-3.7-build-VS22-x64.patch
この後、ソースツリーをWindowsへ移し替えて 同梱されているバッチファイルのmake.batを実行する(⌒_⌒; )
A>make.bat
こうするとgrep.exeが出来上がる。 ただ、このままでは引数にワイルドーカードが使えないので、 バッチファイルの末尾のLINKの部分に setargv.objを追加する。
link /LTCG /nologo .\libgreputils.a /OUT:grep.exe
.\src\dfasearch.obj .\src\grep.obj .\src\kwsearch.obj
.\src\kwset.obj .\src\searchutils.obj setargv.obj
また、ランタイム不要の単体実行ファイルにするには、 バッチファイル中の"cl"を"cl /MT"に置き換える。
:%s/^cl/cl \/MT/
make clean に該当するコンパイルの後始末は以下のようなバッチファイルで行う。
PUSHD LIB
FOR /R %%F IN (*.obj) DO DEL /F %%F
POPD
PUSHD SRC
FOR /R %%F IN (*.obj) DO DEL /F %%F
POPD
DEL /F *.exe
ちなみに、パッチによって埋め込まれたフルパスを自分の環境の環境変数INCLUDEを参照することで自動的に自前コンパイル可能な状態に修正するRubyスクリプトは以下の通り。これをソースツリートップの下のlibの下に保存して実行する。
#coding: cp932
require 'find'
incs = ENV['INCLUDE'].split(';')#.map { |inc| inc.gsub('\\', '/') }
Find.find('.') { |path|
if File.file?(path) then
if File.extname(path) =~ /\.[ch]$/ then
txt = open(path).read
txt.force_encoding(Encoding::ASCII_8BIT)
txt = txt.chomp.split(/\n/)
modified = nil
txt.each_index { |n|
if m = /^(\s*[#]\s*include\s+["<])([^>"]+)([>"].*)$/.match(txt[n]) then
if txt[n] =~ /Program Files/i then
bname = File.basename(m[2])
tname = nil
incs.each { |inc|
if File.exist?("#{inc}\\#{bname}") then
tname = "#{inc}\\#{bname}"
txt[n] = m[1] + tname + m[3]
puts "MODIFY:#{txt[n]}"
modified = true;
break
end
}
end
... keep reading on reddit ➡I need to find letters A-Z and spaces only one character after "7@9a" in a .txt file. So far I've managed to put up this: grep -oPa "(?<=[7@9a])[A-Z]" file.txt, but this returns characters after every single one of the "keys" and not after a string. What do I need to change?
Example: nn147@9aAxyyy --> has to return A
Ive tested this regular expression on regexr.com and I get a match however it doesn't seem to be working within a grep
I have alert.txt which I am looking to grep using the following
grep 'Disk drive [/\w]+ is at \d+% full
However the grep doesn't return anything.
I'm assuming it's because grep doesn't have this functionality. Is there a better way of doing this compatible with a grep command.
Hi,
I have a file from which I need to extract matching brackets, but I cannot find the right way to do it.
Here is my file content :
@article{entry1,
author = {author1, author2, etc},
year = {2021},
month = {01},
pages = {},
title = {Title here},
volume = {15},
isbn = {000-0-00000-000-0},
journal = {Some journal},
doi = {11.1111/1.1111-111}
}
@article{entry2,
author = {author3, author4, etc},
year = {2000},
month = {01},
pages = {},
title = {Title of the second entry},
volume = {1},
isbn = {333-3-33333-333-3},
journal = {Some other journal},
doi = {44.4444/4.4444-444}
}
And I need to match the following pattern :
the @ symbol, then letters, then an opening bracket, the "entry1", and everything up to the closing bracket
I would expect something like this :
@[A-Za-z]{entry1
(then something to go to the matching bracket)
The output of the grep search should look like this :
@article{entry1,
author = {author1, author2, etc},
year = {2021},
month = {01},
pages = {},
title = {Title here},
volume = {15},
isbn = {000-0-00000-000-0},
journal = {Some journal},
doi = {11.1111/1.1111-111}
}
I found this post (https://unix.stackexchange.com/questions/147662/grep-upto-matching-brackets) but I cannot adapt it to have the "entry1" inside of the matching brackets.
Could you please help me ?
Thank you
Hello,
we're hosting Git repos with Bitbucket. Regarding to Log4Shell, I'd like to search for log4j in those repos. My idea is to generate a list of all affected repos so that our developers can also check their version on the internal projects.
The data directory contains a subfolder shared/data/repositories with all the binary repo data. Each repo contains files like HEAD, config, repository-config and the folders hooks,objects,refs. Since Git uses a binary format, I cannot simply grep for log4j over those files. So I tried to use git grep, but it doesn't seem to work too:
/opt/bitbucket_data/shared/data/repositories/999 # git grep --all-match log4j
fatal: Couldn't JIT the PCRE2 pattern 'log4j', got '-48'
Am I using it wrong? Is there another way how I could search through the binary git data in all of the repos on the server?
Is there any keymap for telescope so that I can press that when my cursor is over some word and search that in :Telescope grep_string
or if there is something similar to ctrl-r ctrl-w
in command line mode to get the current word over cursor.
Hello,
I have managed to successfully get to the final step in setting up my Algorand node following this guide:
https://developer.algorand.org/docs/run-a-node/participate/online/
At the step: Run a node>Participate in consensus>Register online>Check that the node is participating
I am running the command: "grep 'VoteBroadcast' node.log" in the data directory.
The command is going through successfully without errors but it's not returning any output like in the example. Does this mean I did something wrong?
Hi all,
Depending on the project, I often want to start my live_grep
search in a particular folder (e.g: only search in main
and not in test
). I know that I can set a configuration to ignore/exclude certain folders in telescope or set a flag for rg
. However, the folder which should be ignored changes frequently. Therefore I'm looking for a solution where I can set the ignored folder on demand. I could create a .rgignore
and change it depending on my search but this seems quite cumbersome.
Do you guys and girls know any way to exclude files directly from the telescope prompt or have and other ideas to achieve this?
Thanks!
Your server is now running two services: the sshd (Secure Shell Daemon) service that you use to login; and the Apache2 web server. Both of these services are generating logs as you and others access your server - and these are text files which we can analyse using some simple tools.
Plain text files are a key part of "the Unix way" and there are many small "tools" to allow you to easily edit, sort, search and otherwise manipulate them. Today we’ll use grep
, cat
, more
, less
, cut
, awk
and tail
to slice and dice your logs.
The grep
command is famous for being extremely powerful and handy, but also because its "nerdy" name is typical of Unix/Linux conventions.
cat
like this: cat /var/log/apache2/access.log
less
to open the same file, like this: less /var/log/apache2/access.log
- and move up and down through the file with your arrow keys, then use “q” to quit.less
, look at a file, but practice confidently moving around using gg, GG and /, n and N (to go to the top of the file, bottom of the file, to search for something and to hop to the next "hit" or back to the previous one)sudo
usage by viewing /var/log/auth.log
with less
tail /var/log/apache2/access.log
(yes, there's also a head
command!)tail -f /var/log/apache2/access.log
(while accessing your server’s web page in a browser)|
(pipe) symbolcat
, but pipe that output to grep
with a search term - like this: cat /var/log/auth.log | grep "authenticating"
grep "authenticating" /var/log/auth.log
grep "authenticating" /var/log/auth.log | grep "root"
cut
command to select out most interesting portions of each line by specifying "-d" (delimiter) and "-f" (field) - like: grep "authenticating" /var/log/auth.log| grep "root"| cut -f 10- -d" "
(field 10 onwards, where the delimiter between field is the " " character). This approach can be very useful in extracting useful information from logI know how to call Telescope for a particular directory, e.g.
Telescope live_grep cwd=nvim/plugin
but I've not figured out a way yet to call it on a single file.
Can anyone help?
Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.