Questions tagged [grep]

grep is a Unix command-line utility that searches input for lines matching (or not) a regular expression and prints the results.  Use this tag for questions about how to use grep features, how to write regular expressions that work with grep, and general usage.  Because grep is now available in Unix-like environments (e.g., Cygwin on Windows), you can also use this tag for compatibility questions, and differences between versions and software environments.

Filter by
Sorted by
Tagged with
0
votes
1answer
23 views

grep for lines in shell script, send to xargs with $1 set

I have a shell script (I use GNU bash 4.4.20 on Ubuntu 18.04) with a list of commands I often run, e.g.: sudo program1 $1 foo arg1 sudo program2 $1 foo arg2 sudo program1 $1 bar arg3 sudo program2 $1 ...
0
votes
1answer
16 views

grep output “begin” option

Is there an option to get the output from the grep but that output needs to start with the word that I am searching for? This is really hard to explain so let me give an example here: When you want to ...
1
vote
1answer
217 views

`grep -z -a -b -P --only-matching 'LUKS\xba\xbe'` doesn't match `LUKS\xba\xbe…`

I don't understand (based on https://ubuntuforums.org/showthread.php?t=1643334): % grep -a -b -P --only-matching 'LUKS\xba\xbe' /dev/sde ### does not match % echo -e 'LUKS\xba\xbe...' | grep -a -b -P ...
-1
votes
1answer
32 views

Grep with option -P in busybox

I want to run a grep command with option -P in a BusyBox v1.31.1 () multi-call binary inside a kubernetes pod with the image curlimages/curl:7.75.0 curl -s -X GET "https://api.cloudflare.com/...
1
vote
2answers
23 views

Extract key from key-value pair

I have a file looking like that. mke_version = "3.3.7" msr_version = "2.8.5" mcr_version = "19.03.14" I want to print from file only key ...
0
votes
0answers
16 views

How to cancel invalid panelize command in Midnight Commander

I'm trying to use the panelize command in Midnight Commander, but I typed an invalid command: grep execute -- $(find /var/www/html/magento2/ -ipath Controller/) If I type the command in Bash, it ...
0
votes
0answers
27 views

Syntax error, unexpected token `else'

#!/bin/bash if find /data -name "*.log" -exec grep "MySQL error code: 1205" {} \; then find /data -name "*.log" -exec grep "MySQL error code: 1205" {} \; | ...
1
vote
0answers
44 views

grep and awk are not displaying output in terminal

When trying to grep Record in .txt file simply $ grep 'Record' file.txt $ it goes to the next line without any output or error (I've tried to write output in file, but it is empty) I've tried also to ...
0
votes
2answers
99 views

Is there a way to filter the command history in Windows using cmder?

In Linux I can doing something like history | grep abc and that will only bring up the commands that start with 'abc'. With Windows in cmder, I can bring up the history of commands with the history ...
1
vote
0answers
60 views

bash grep not finding all instances of gene

I have a file1 which has gene names: Appl Bsg mt:CoI mt:CoII mt:CoIII I have file2 which has all matches of those gene names in the genome: "FBgn0000108"; "Appl"; "...
0
votes
1answer
20 views

How do I look for a word, which letters are seperated by spaces?

I want to grep over pdf files for specific search terms. I'm using pdfgrep for this task, which works quite fine. However, sometimes words are specified with spaces between each letter. E.g.: ...
0
votes
0answers
42 views

Grep not returning any value

I came across very weird situation where I am not getting grep's output. I have a file with below content: Name AAKHJJHGJH JHJH154855 HHG87765787 When I do grep "AAKHJJHGJH" filename ...
0
votes
2answers
121 views

How to exclude dot underscore ._ files when using `find`?

I'm using this command: ls -R |find . -name "*.avi*" -or -name "*.mp4*" -or -name "*.mkv*" > movies.txt The problem is the movies are listed twice! Example: ./_NEW/...
0
votes
0answers
18 views

Exclude subdirectory not working with grep command

This works for me, in that it excludes the "foo" directory from the root directory of the search: grep -rn --exclude-dir=foo 'custom' However this doesn't work: grep -rn --exclude-dir=foo/...
0
votes
1answer
45 views

Why matches grep pattern '[^a-z0-9\.\/_\-\ +@)(&]' matches '-'

I'm trying to find files with ridiculous filenames. I'm using this command: find . -type f | egrep -i '[^a-z0-9\.\/_\-\ +@)(&]' but I'm a little bit dumstruck because it matches filenames ...
0
votes
1answer
27 views

Find number of files that contain certain String

I have a directory containing a vast amount of xml files. I would now like to find the number of files (and optionally the names of said files) that contain a certain string. XML tags do not really ...
0
votes
3answers
116 views

grep forward slash to forward slash

I have HTML files that contain a lot of URLs. I try to grep only the forward slash to end with forward slash like: "/index.php/pub/xx/en/details/123456/" "/index.php/pub/xx/en/details/...
0
votes
1answer
63 views

How to use “find” to print the path instead of “grep” in case of matching file contents

For example, I need to print the paths of all the user's files that contain the word hello. Must use find Use the find command to search, and grep to print the path: find ~ -type f -exec grep -lis &...
1
vote
1answer
49 views

Would you expect different outputs from these two command chains?

I'm working on a project for a linux class, we're writing a script to pull stats from a log file. This specific command chain is to get the number of users running MSIE 6.0. I'm wondering why I'm ...
2
votes
0answers
38 views

Full-text searching, how fast one can find “Linus Torvalds” into the linux kernel? [closed]

Three things: Currently, what are the fastest full-text search tools? Are there full-text search tools capable of reporting fullpaths of files containing hit(s), FAST? Is Linus Torvalds right about ...
0
votes
1answer
40 views

Grep with a variable in a script

I have this code that returns the number of files in a directory with the name wordpress.*.tar.gz This code works NUM_BACKUPS="$(ls -l ${POOL_PATH}/${BACKUP_PATH} | grep -c '\wordpress.*.tar.gz$')...
1
vote
1answer
250 views

GitHub: Trying to use pre-commit hook to prevent users from checking in certain file types, hook fails to work

I need to set a pre-commit trigger to prevent certain file types from being committed to my GitHub Repository at all. I have already set .gitignore, which works for what it does, but that can be ...
0
votes
0answers
19 views

How do you use grep for getting your two outputs tab separated on one line?

grep -oP '(?<=name="Zip">).*(?=<)|(?<=name="DelPrf">)\d+' Text.xml the result of the above command will be alternating values of Delivery preference and zip code so ...
-1
votes
2answers
76 views

Parsing file with RegEx for multiple line matches with capture groups

I have some files. I want to match the following string from each file, which is on two lines. <TagA>A7C</TagA> <!--<TagA>70458548767</TagA>--> However, I want grep ...
0
votes
1answer
114 views

How to use grep to print lines until matching closing bracket?

I have a document that has code like this: Some words. \NOTETAKING{ some text This is some {} text. This is more text \this{}. } Some more words. How can I use grep to match the line starting ...
0
votes
0answers
19 views

Filter whole line from output in command line

I'm trying to find a bottleneck caused by some MySQL query, which oftentimes overloads the web server. Then I found this useful command: mysqladmin -u myusername -p -i 1 processlist which every ...
0
votes
1answer
30 views

grep for same occurrence more than once

Is it possible to grep or awk for more than 1 occurrence of the same string from a file? awk '/$STRING|$STRING/' file grep -e $STRING -e $STRING file I tried other options but still not able to get ...
0
votes
0answers
39 views

Select part of PATH variable in bash_profile and insert it into another file

Fairly new to anything Linux. I have a path variable in my users' bash profile that we'd like to utilize from some of our scripts on the server. The part of the script that I'm changing is as follows ...
1
vote
2answers
46 views

recursive grep does not list matches from some files

I am using GNU grep 3.4 to find scripts that contain a certain pattern. For this, I call grep recursively like so grep -rin . -e "pattern" The pattern is just a word, no regular expression....
0
votes
2answers
47 views

Why is the output of word count not accurate when assigned to alias?

I use squeue to display jobs like below and I would like to count the number of running jobs (according to the fifth) column. The command squeue -h -u $USER | awk '{print $5}' | grep R | wc -l does ...
1
vote
1answer
56 views

AWK/SED/GREP - print M lines after the Nth occurrence of a match

I am looking to display M lines after the Nth occurrence of a match. Actually I need to do this in order to split a file containing Nth <regex> always followed by M lines into Nth different ...
0
votes
3answers
629 views

How do I filter an XML file to find all of one type of tag with any invalid values?

I was messing around with notepad++, but seem to find an easy way to do this. I think grep might work, but I an not totally sure how. I have a file, that has certain tags, I want to find all of the ...
5
votes
1answer
429 views

Inverse grep using a pattern file doesn't show non-matches

I have two nearly identical files, "foo" and "bar". Each file has thousands of lines, one number each line. If I sort and then diff both files, this is the result: $ diff foo bar ...
1
vote
1answer
671 views

xargs and git issues in windows powershell

I've been using the following command to delete any merged git branches: git branch --merged | grep -v "\*" | grep -v "master" | grep -v "staging" | xargs -n 1 git branch ...
0
votes
1answer
55 views

'grep' command not highlighting User input word in the Search result

I am trying to write shell script as below to search user inputted word and highlight the word in the search result - User input: echo -n -e "What you wanna search:" read userinput Save the ...
3
votes
2answers
135 views

how do I write a line number divisible by 3 in bash from an input file?

Create a shell script which prints the line contents when the line number is divisible by 3 from an input file. Assume the first line is line 1. At the end of the script, if the total number of lines ...
1
vote
2answers
58 views

GREP for a timestamp within parentheses

I need to create a GREP to search a doc for timestamps. However, these timestamps are in parentheses. Ex. (23:54) or (02:03) etc. The numbers within the parentheses vary and I need to find them all....
1
vote
1answer
82 views

Why does this combination of tail and grep freeze my ssh session after a while?

sudo tail -f -n0 /var/log/nginx/access.log | grep -Ev '1.2.3.4' I have an nginx.log that I need to monitor for all lines except those with my own IP (1.2.3.4). The web server doesn't see much ...
0
votes
1answer
24 views

How to set up email notifications for certain strings in Nginx access.log?

I would like to be notified every time a line with a certain string appears in my Nginx's access.log. I imagine a certain combination of a continuously running tail + grep -w 'foobar' /var/log/nginx/...
0
votes
1answer
78 views

grep cannot find a known string in a MS-Word file even with the -a option

I have MS-Word file including the string "Abekat" The entire content of the file (test.docx) is in fact just: "This file includes the word Abekat". Standing in the same directory as my target file (...
0
votes
1answer
37 views

grep AND OR operators combined with IP addresses

I'm trying to find a way of streamlining my grep searches and be more granualar. An example of what I want to achieve: a netstat output searching for a particular IP AND the word established OR ...
1
vote
1answer
52 views

Display dirs tree based on a file content

$ find ./ | tac ./dir1/file -> "abc" ./dir1 ./dir2/file - > "abc" ./dir2 ./dir3/file -> "xyz" ./dir3/dir3_1/file - > "abc" ./dir3/dir3_1 ./dir3 or $ tree ├── dir1 │   └── file -> "...
5
votes
3answers
923 views

How can I get the output of `du -c` without the word `total`?

I want to get the total size of a directory and all directories inside it. I am using the command du -h -c "$input_variable" | grep total It prints the results and the word total. How do I get the ...
0
votes
1answer
99 views

Troubleshooting grep not returning whole lines during search?

I have two tab delimited txt files- FileA has 30,000 lines and 10 columns. FileB has 600 lines and 1 column. My goal is to search the 30,000 lines of FileA using the search terms in FileB and output ...
0
votes
1answer
35 views

assistance in grep-ing a file for “!!!”

I am attempting to search a large file for the lines which contain the string !!! and output those lines to a different file. However, the shell is interpreting the !!! as a shebang and inserting my ...
0
votes
0answers
237 views

Grep unix time range gives invalid range error

I need to grep this time range: 2020-04-27T20:29:27 - 2020-04-27T20:3x (any time after 30) However this grep gives me an invalid time range error: egrep MESSAGE_SENT company-runtime-cdrs*.log | grep ...
0
votes
2answers
123 views

Why is this grep skipped after wget?

I'm trying to grep a string from the HTML output from wget in order to concatenate a URL together. Using the suggestions here I tried wget -O - https://www.printable-puzzles.com/download.php?p=cw2&...
0
votes
1answer
29 views

Why isn't grep agreeing with other regex tools?

I am currently trying to write a grep command to find IP addresses in its input. My regex is \d+\.\d+\.\d+\.\d+ which works as expected in an online tester with all flavors of regex. Yet, when I ...
0
votes
1answer
50 views

Grepping specific lines with the same pattern

I am currently writing a bash script to grep out certain lines as shown in bold. However when I do a grep 'number', all the irrelevant lines will appear as well. Is there a way to just grep out the ...
0
votes
1answer
236 views

grep for pattern including carriage return on a Mac

I want to search files for colon followed by carriage return followed by dash. I am using macOS (so it's BSD grep). I would have thought grep -l ":\n-" filename-pattern would work, but it doesn'...

1
2 3 4 5
21