Questions tagged [grep]
grep is a command-line text-search utility originally written for Unix. It uses regular expressions to match text, and is commonly used as a filter in pipelines. Use this tag only if your question relates to programming using grep or grep-based APIs. Questions relating to using or troubleshooting grep command-line options itself are off-topic.
16,576
questions
1
vote
1
answer
31
views
(standart input) shown instead file name with grep -iHn "ERROR" and a second grep -vH "filter" shows (standard input) and no longer the file name
What I try to do:
Find all log files from this day
Then grep "ERROR" in the files
Then grep -v "Not this line containing the filter" as Filter in result of the first grep command
...
-3
votes
0
answers
38
views
Output lines from a file that match pattern 1 and not pattern 2 in linux [duplicate]
I have a text file that has a bunch of lines. I used grep to print lines matching pattern 1 to a second file. I want to modify the command to exclude the lines the match pattern 2. So the requirement ...
0
votes
3
answers
85
views
How to find strings in multiple lines of txt file then add all to new csv line
I have thousands of txt files that were converted from emails that included a "Contact Us" form. I need to find/select strings in the second "column", but the number of lines to ...
-1
votes
0
answers
38
views
How to find a pattern within nested delimiter pairs using grep or similar?
I'd like to match a pattern occurring within an arbitrary nesting of delimiter pairs (in my case, braces/curly brackets). For example, if the pattern was "abc", I'd like to match any of the ...
0
votes
0
answers
37
views
capture hash value from git log --oneline --graph using regex [duplicate]
When running git log --oneline --graph you can get something like this
* 7e5dbb0 Merge
|\
| * c873a96 My
| * f5817ba Amazing
* | f6a34ac Feature
|/
* f5a51ce Other stuff
I want to take that and ...
0
votes
1
answer
31
views
Bash command substitution issues
I'm writing a Python script to parse various logs across different hosts.
I can successfully run bash scripts via Python's subprocess module, however, I want to minimize the number of ssh calls, so I'...
-1
votes
3
answers
55
views
How to use grep in specific case? [closed]
How to extract part of the search with grep.
Example: I would like to extract lines with "bc" in them
but not lines containing "abc".
My not-so-elegant solution is:
cat file.txt | ...
0
votes
0
answers
24
views
Github Action Logs
I have integrated playwright zephyr reporter and run my tests using github actions.
I use https://github.com/elaichenkov/playwright-zephyr plugin and it prints following logs in console.
In next step ...
0
votes
1
answer
41
views
Finding a specific item in a list using CLI
I am using the CLI and the determined library, and I want to find if a certain Username exists.
I tried the commands below, but I dont get the line printed although I'm sure the Username exists.
...
0
votes
1
answer
40
views
How to create an "alias" that search for an "alias"
I need to create an alias that receive a parameter, then search for all alias that has that parameter in this way: alias+space+parameter+"other text"
My aliases:
alias att='alias | grep --...
0
votes
0
answers
24
views
Git: Display a list of branches found using `grep`, and allow selection by entering the branch number
I am running next command to find branch by text pattern and auto checkout it:
git checkout $(git branch | grep search_text | head -n 1)
However, there are cases where more than one branch matches ...
1
vote
3
answers
77
views
Search a list of numbers in a column of another file [duplicate]
I have a list of numbers.
For each number, I want to find it in another file.
But I want to find it only in the 12th column.
I've tried many things, including variable injection :
for line in `cat ...
0
votes
0
answers
16
views
Find catch blocks that return optional empty
I'm using pcregrep to find catch blocks in my java project files that return Optional.empty()
pcregrep -M 'catch.+{(\n|.)+return\s+Optional.empty()}'
This gives
pcregrep: Check your regex for nested ...
0
votes
1
answer
27
views
How to grep a next line json file
I have this multiple json file containing below and i want to capture png with enabled:true status.
"png": {
"enabled": true,
"status": false
},
"jpeg"...
0
votes
0
answers
10
views
Search for specific content in a file present in multiple sub folders - Linux
I have a 'feature_config.json' file which holds flag values for multiple features, something like this:
"feature1": {
"enabled": true
}
"feature2": {
"...
0
votes
2
answers
57
views
use sed group variable within loop for another grep
Context: grep on result of sed grouping, within a loop
grep "blah" x.txt | sed 's/cheese\(.*\)/xlogs\/butter\1.log/g' | while read -r line; do
echo $line;
//TODO: grep -r "$1" ...
0
votes
1
answer
24
views
emacs windows gitbash and cmd.exe shells
I have Emacs for windows. I have GITBASH for windows.
My goal: How can I get Emacs to use the GITBASH version of GREP, when I use M-x grep?
NOTE: For various reasons I cannot put "C:\Program ...
0
votes
1
answer
70
views
how can i tail the last line of multiple log files, only if they have not completed yet?
I have multiple subdirectories, and each has a log file that I want to check, but I only want to check the log files that have not reached the "completed" state. The last line of a completed ...
-1
votes
3
answers
41
views
grep or sed to delete 1 line after a match (but not the match)?
I'm trying to write a command to amend an xml file to remove the first of each pair of lines with a <display-name> occurrence.
In other words, my file looks like...
<?xml version="1.0&...
0
votes
2
answers
50
views
how to grep a specific passage in a line in accordance to another line
I'm currently trying to grep the content of href from an html text. The problem is that href is listed multiple times in the file and therefore I need to grep a line above it.
<tr>
...
-3
votes
2
answers
101
views
extract parts of filenames with regex in bash [closed]
I want to extract some information from filenames using regex in bash, which I will use to rename them according to BIDS. Here are the filenames:
ACC_svs_ECC.nii.gz
ACC_svs_noECC.nii.gz
ACC_svs_ref....
0
votes
1
answer
41
views
CSH loop over results from grep not giving desired outcome
I want to loop over the lines as output by grep cmd from a file. The lines follow a format where there will be a word matched / not matched by the grep and then some other word that some other program ...
0
votes
1
answer
35
views
using grep with a variable containing xml-tags [duplicate]
I have a script that is trying to find a line in a text file. It could be completely alphanumerical, but it's also possible that it contains special characters, mostly < and > as it's sometimes ...
0
votes
1
answer
55
views
copy from text file to other text file , but not owerwiting first 2 lines [duplicate]
I would like to copy the contents of a text file has another text file but do not crush the first 2 lines of the other file, or copy and add the 2 lines to the new file
Exemple:
user1.txt:
Phill
Johne
...
0
votes
1
answer
65
views
Checking for circular dependencies with madge in bitbucket CI
I want to add a step to check for circular dependencies in our bitbucket pipeline, but I'm struggling to come up with a good way to grab the output to throw an error or not
Here are the bitbucket ...
1
vote
5
answers
61
views
How to grep the first string delimited by ''
How to grep the first string within '' in a text file?
in:
path: '', redirectTo: '/login', pathMatch: 'full' },
path: 'login', component: LoginComponent },
path: 'registration',
path: 'employees',
...
1
vote
2
answers
87
views
How to get matched pattern in ugrep
I have created a ugrep command and file
ugrep -Hn -e 'Error:XX234 - \S+\.txt : cannot find user' -e 'Error:XX235 - \S+\.pdf : cannot find data' --format='%f:%n:%o%~' *
File content
1_Error0: ...
0
votes
1
answer
61
views
Does zgrep limit the amount of search patterns?
I have the two following commands.
# 6 million lines
"zgrep -oF -f /projects/lab.mis/index/temp_hg19.inx /projects/incoming/M1_R2.fastq.gz"
# 6 thousand lines
"zgrep -oF -f /projects/...
-1
votes
2
answers
73
views
for zgrep how do I limit per pattern and not the entire match?
I have a file that has about 1000 patterns to match. For each pattern I want to limit for each pattern however when I use the -m option it will find the first 10 and stop. Is there a way to do this in ...
2
votes
2
answers
54
views
How to limit lookbehind to strings which do not start with certain characters
In InDesign, I’m using the GREP expression (?<=.)/(?=.) to locate all occurrences of the slash character / throughout a document.
For example, I want to find the character / in Color/Colour or ...
-1
votes
3
answers
77
views
Optimise text file statistics calculation by combination of grep, awk, cut
My goal is to calculate statistics from the file that contains the following lines:
2024-05-08 11:02:58,731 INFO o.a.j.a.J.Some check: Closest Day: Wed, New quantity for [email protected] is: 1
...
-2
votes
1
answer
81
views
bash grep can return an empty space, how to substitute the empty space for a string?
I am attempting to grep an inbox for survey results, in which the subject will include the answer to the following question:
"The answer to your question is ___"
The answered question will ...
-5
votes
2
answers
52
views
(LINUX) use echo and grep to delete multiple files
I have 4 files in my current directory: '#cos#', ab.txt, cos~, file.txt. I want to delete all files with the word "cos" in them, which just also happen to be the only words with the letters '...
1
vote
3
answers
157
views
Get the count of unique words in a file using grep and wc
need command to find the count of unique words in a file using grep
Tried using grep along with uniq and sort but need to find a way to use only grep and wc commands.these are the two ways in which am ...
-1
votes
3
answers
37
views
How to extract sequence cluster numbers containing a specific string in the ID from a cluster file in bash?
I have a cluster file for sequences clustering at 100% sequence identity, each containing sequence clusters denoted by cluster numbers followed by IDs. Here's an example of the file format:
>...
1
vote
1
answer
43
views
pass shell variable to -A flag in grep [closed]
I have a set of .sdf (molecular) files that have varying numbers of atomic coordinates that I need to grep out. The header information of the file provides the number of atoms in the file along with a ...
2
votes
3
answers
136
views
Spelling Bee game regex
In the NYTimes Spelling Bee game, you have to make words (4+ letters long) using a set of 7 letters, one of which must be used in the word. This is fairly trivial to make a regex for:
grep '^[bluntam]\...
1
vote
2
answers
69
views
grep condition to grab certain text only
so i am trying to grab certain output from grep command
here is the command i am trying
nslookup -type=TXT "_dmarc.$domain" | grep -Eo '\s*reject|\s*quarantine|\s*none|\s*no answer' || echo &...
2
votes
3
answers
125
views
Regular expression to match specific words seperated by spaces
I have a list of say 5 words (foo bar foobar footable somebar). This list of words will be provided as a string each separated by space and in any order. I need a regex matching below requirements
...
0
votes
2
answers
67
views
Bitbucket pipeline fails for grep command in exclude hidden directory
I have the following command to run:
grep -r -n --exclude-dir='.test' ERROR . >> errors.txt
This works fine on the terminal but when I run this on bitbucket pipeline via yml file, it fails with ...
0
votes
4
answers
55
views
Extract SET var = func(x, y, z); from code, possibly with newlines
I have to do a recursive search for a word and then select the line/lines until the ).
My file looks like below and the output is mentioned below.
SET var1 = FormatValue(A1,B1,B2);
SET var2 = ...
0
votes
1
answer
53
views
How can you use regex to find a dynamic string that is not preceded by something? (negative lookbehind fails)
Here are some strings (not lines!) that I need to match. (The dots represent other strings that will not match.)
... ThisIsAString ...
... AnotherString ...
Here are some strings that I need to avoid:...
-2
votes
1
answer
36
views
Flag --include in grep does not accept numerous entries
Why is it possible to use:
grep -rinHI --exclude={\*.h} pattern
grep pattern -r --include=\*.cpp --include=\*.h rootdir
(source: https://stackoverflow.com/a/221929/22132012)
But not (it does not ...
0
votes
0
answers
25
views
bash: grep latest file in a directory over ssh [duplicate]
I have a code where I can grep a very specific file over ssh:
ssh ${username}@${host} << -EOF
grep -n ${text} ${filename}
EOF
which will output the desired text. However, now I want to do the ...
0
votes
1
answer
50
views
Recursive search and replace a string with dot in text files on Mac
Team, I see there are multiple similar questions but I did try some answers and still not able to get what I want. I want to replace a text as "product-ui-test-creds.json" to "vaulted-...
1
vote
3
answers
80
views
Is there a shortcut to open vim and then jump to line ”num“ as ":num"?
I used to search words in my code tree by grep -rn. And the output is just as below.
"{filename}:{num}:{line content}"
Sometimes I will to open the file with vim, and jump to the line num ...
1
vote
3
answers
150
views
pgrep matches undesired patterns
This is the beginning of a script for determining whether to run tmux, it has been modified for debugging purposes:
(no tmux instance is ever running in this test example)
#!/bin/bash -x
if [[ -n &...
0
votes
1
answer
29
views
grep command until a specific column
Can someone help with how I can use Grep cmd to get a specific output.
My cmd -------- ps -aef | grep gen | grep -v grep
cor 3957 1 0 Mar01 ? 02:04:07 gen nam=RS grp=81
mre 103189 ...
-1
votes
1
answer
42
views
How to grep a specific data
I want to grep python extensions with their names in a large data of words and sentences, and I tried with find and grep commands but I couldn't do that. Can anyone tell me what should I do?
By the ...
0
votes
0
answers
46
views
Confused about why the regex pattern does not works [duplicate]
I'm using npm ls -a which gives the following ouput:
└─┬ [email protected]
├── [email protected]
└── [email protected]
I'm trying to extract all the dependencies and store it in a file with the following ...