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
1 answer
18 views

How to find a multiline partial regex match in multiple files?

I have a bunch of files. Every file can contain one or more matches for the following regex pattern: (foo)([\s\S]+)(bar) The matches can contain line breaks / multiple lines. I want to extract all ...
user avatar
  • 1,309
0 votes
0 answers
21 views

Windows: Grep inside for loop for directories list? [closed]

I am using Windows 7 x64 bits and ConEmu Console Emulator which somehow accepts some of the Linux bash commands. I have a directory_A which contains over 60.000 (subdir_A, subdir_B, subdir_C and so ...
user avatar
  • 3
0 votes
0 answers
23 views

Grepping byte offset values for data blocks of specific type in a binary file, but it's skipping blocks containing any byte larger than 127 [or 0x7F]

I have a binary file containing blocks of data. The first four bytes of each block contains a fixed byte string, five bytes after that contains the block's "type" byte. I want to find out ...
user avatar
  • 1
0 votes
1 answer
11 views

Skip a character from character class

I am using following grep code to search single arabic characters only in Adobe Indesign: \b[\x{0600}-\x{06FF}\x{0750}-\x{077F}]{1}\b All is working fine except that I want to skip just one character ...
user avatar
  • 29
0 votes
1 answer
31 views

Removing Duplicate from File

I have two files fileA and fileb FILEA 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4 5.5.5.5 FILEB 4.4.4.4 2.2.2.2 Output should be 1.1.1.1 3.3.3.3 5.5.5.5 Size of File A is around 60GB and Size of File B is 1GB ...
user avatar
  • 15
0 votes
0 answers
15 views

when running "LC_ALL=C.UTF-8 egrep -axv '.*'" to detect non-UTF8 characters how can I determine the exact character that caused the detection?

I frequently use this command: LC_ALL=C.UTF-8 egrep -laxv '.*' filename this tells me if the file contains any non-UTF8 characters (actually I usually use this in conjunction with find to scan many ...
user avatar
0 votes
1 answer
30 views

Highlight words in sentence

I have few sections of a book which contains matter of following format: Meanings 1:- Appreciate : understand value of something, situation, to be grateful. Regard:to think of somebody, best wishes. ...
user avatar
  • 29
0 votes
0 answers
52 views

macOS terminal: show filename with colors when using grep

When using Ubuntu I get these colors when using grep (grep -r "MSP" .): I want the same result when using macOS Monterey. I tried to add export GREP_OPTIONS='--color=auto' to my bash ...
user avatar
  • 101
0 votes
2 answers
56 views

How can I see the lines where matching patterns occur in grep for multiple patterns in multiple directories

Thanks for all the input and effort, I've been able to find a solution to my "problem". find . -type f -name '*.csv' -print0 | xargs -r0 grep -rn string1 | grep string2 | grep string3 ...
user avatar
  • 1
0 votes
1 answer
31 views

GREP_COLORS does not work on GNU grep Mac OS

On Linux, I get beautiful coloring that makes the file name and line numbers easy to distinguish from the file content: I have set GREP_COLORS on Mac OS X for my GNU grep installation (via homebrew) ...
user avatar
0 votes
1 answer
84 views

How to alter "grep" colour scheme on Windows-10 Ubuntu WSL app

I'd like to alter the colour scheme of my grep results on my Windows Subsystem for Linux (WSL, Ubuntu app on a Windows-10 computer). My .bashrc file contains the following entry: alias grep='grep --...
user avatar
  • 1,462
0 votes
1 answer
43 views

Piping PCRE grep into sed

I wanna sed this file, but the BRE in sed is not working as well as I hope. What I have now is basically just : $ cat Dungeon | grep -P -o '<\/.*?>' My question is how do I sed this? I want to ...
user avatar
2 votes
1 answer
40 views

Delete lines using RegEx

I have a situation mentioned below. I need the keep the sentences/lines starting with {digits} and delete rest of the lines. I tried this but not working. Find: [^({\d{1,2}}.+?\r)] Replace:$1 The list ...
user avatar
  • 29
0 votes
1 answer
91 views

Is there a limit for a line length for grep command to process correctly?

While I'm checking the results of my biostar implementation for searching primes in a fasta file, I've seen a strange result. I've originally a 70 column file and converted it into a file that has ...
user avatar
  • 375
0 votes
1 answer
26 views

Finding primers on fasta files with position, line and column information

I've some fasta files which contain exactly 80 columns per line. Forget about the definition line that starts > and consider the rest that has around 1250000 lines. I needed to find some primers ...
user avatar
  • 375
0 votes
1 answer
110 views

Searching for strings in a dd image, extracting data from it

I am trying to recover the contents of a text file that became corrupt following a power outage. The file size is still correct (14 MB), but the text in the lower half of it has been replaced by ...
user avatar
1 vote
0 answers
45 views

grep / ripgrep - limit number of characters

I have a set of very big files that I want to search for a specific string. I know that the string is going to be present very close to the beginning of the file. It's usually at the very start of the ...
user avatar
  • 5,107
0 votes
1 answer
82 views

Grep command inaccurate or bad command? Windows WSL

I am using grep command in Windows WSL and it seems to be inaccurate. The command is to remove matching lines from file1 from file2 and output of those lines in file3 (text files) grep -v -f file2.txt ...
user avatar
0 votes
0 answers
34 views

grep word and regex from a file

I have a file that has some server names. Some servers are with regex and some are without. I am trying to grep if the server is present in that file or not and I only have server names with me. My ...
user avatar
  • 357
2 votes
2 answers
169 views

grep to match two occurrences of the same pattern with a certain number of characters in between

I have a text file, test that contains the following string MDXXXXXMD though in general, X could be any character and M could also be F. I'm trying to select for this string with the following grep ...
user avatar
0 votes
1 answer
50 views

Extract all emails from a text document

I have a document that contains text and HTML tags, and there is are a lot of tags like <label>abc@gmail.com</label> How do I extract all the emails from this document using Linux commands....
user avatar
  • 1
1 vote
2 answers
58 views

What is the practical usage difference between "grep -e" and "grep"?

I have read the manual, but still I am not sure how it works. It says -e pattern, --regexp=pattern Specify a pattern used during the search of the input: an input line is selected if it matches any ...
user avatar
  • 399
1 vote
1 answer
155 views

Keep Color output with grep at systemctl status

I'm trying to get the original color of the output of this command with grep: sudo systemctl status telegraf | grep -e ● -e Active Output of command with this command the output is red, but i want it ...
user avatar
0 votes
1 answer
467 views

how to grep with color (--color=always) except when redirecting the output to a file

Is there a trick (probably a zsh function) to make a single grep command behave this way? if grep output is written to the terminal, or is piped to another command (usually less -R) -> use color ...
user avatar
0 votes
0 answers
165 views

Output of dmesg | grep ath10k shows lot of errors (Ubuntu 20.04)

My Wifi is really slow in Ubuntu 20.04 so my driver is ath10k_pci as per: lshw -C network *-network description: Wireless interface product: QCA6174 802.11ac Wireless ...
user avatar
0 votes
2 answers
39 views

Find files in git that have entry in .editorconfig

I want to find all of the files in git that have some extensions. The list of extensions is generated from my .editorconfig file. Say I have a list of file extensions such as: .css .html .java .js (...
user avatar
0 votes
3 answers
349 views

How to execute kill `ps -ef | grep 1.sh` command as SUDO SU from batch file through Putty terminal to kill ALL process, with given name not only 1st?

I try use this command: start "" putty.exe -ssh -load NameOfSessionInPutty -m "C:\Program Files\PuTTY\MYCOMMAND.txt" -t MYCOMMAND.txt contains: sudo su - -c "kill `ps -ef | ...
user avatar
  • 11
1 vote
1 answer
150 views

How to use grep with -f flag

I want to user grep with -f flag. I run like this: grep -f my_file.txt * my_file.txt has a few records that exist in some of * hence I expected to see it. In my case ... it behaviors weird. I.e. it ...
user avatar
  • 571
0 votes
0 answers
76 views

Is there a way to use RipGrep (or a similar tool) et all to search for a pattern, *but ignore results inside comments?*

I'm a regular user of RipGrep rg, but one thing I can never figure out, and regularly find myself wanting, is to search only in lines that aren't comments. Unfortunately, It doesn't look like that's ...
user avatar
  • 1,925
0 votes
0 answers
419 views

Easiest way to grep IPv6 / shortest regex that matches IPv6 (invalid address not a big deal)

I want to grep IPv6 addresess from log files that only contain valid IPv6 addresses that someone connected from (and also contains lines with IPv4 and many other lines without any IP, eg. /var/log/...
user avatar
  • 1,993
0 votes
1 answer
69 views

will `grep -r /` avoid /dev/urandom & co?

(not sure if this question belongs on superuser or unix.stackexchange, if i'm in the wrong place, please let me know) as the title says, is grep -r / -e foo going to avoid /dev/urandom /dev/zero /dev/...
user avatar
1 vote
1 answer
33 views

Grep between characters to find error

I am trying to locate PHP code that will throw error on a update example of PHP code $variable[inside] should be $variable['inside'] im trying to scan through the files using grep to solve them but ...
user avatar
  • 21
2 votes
2 answers
170 views

Search term in specific line in multiple files

I would like to search a text in multiple files (within a directory) at a certain line number. Example: I have ~100 Script Files in a directory (C:\Scripts) and I would like to scan all of these files ...
user avatar
0 votes
0 answers
26 views

How to grep a binary dump from a file in another binary file

I have a binary dump in file.bin. I want to see whether the whole file.bin is there in another binary file called target.bin. I tried the following: grep -F --binary -f file.bin target.bin It just ...
user avatar
  • 11
0 votes
1 answer
63 views

Odd behavior with grep -q in a bash script

I'm trying to write a small bash script that will check if each element of a sequence of numbers is in a given file, and print the ones that aren't. find_missing.sh: #!/bin/bash for num in {1..5}; do ...
user avatar
0 votes
0 answers
27 views

How do I find multiple instances of a phrase using RegEx or Grep search?

I have thousands of HTML files and I need to search through them and find which files contain typeof="ktp:AnswerCorrect" more than once. I'm using Oxygen XML Editor to search but I can't ...
user avatar
0 votes
1 answer
34 views

Weird grep behavior with CJK characters? (bash)

grep fails to match certain strings with CJK characters. For example. Create a text file with content below: ==ShellType.サモナ\u30FC== Use grep. >> grep "ShellType.サモナ\u30FC" ...
user avatar
1 vote
1 answer
136 views

Grep backreference questions

For a text file like: there is a blue beach ball there is a green beach ball there is a blue and green beach ball there is a blue and blue beach ball In a Grep backreference command, like grep -E '(...
user avatar
0 votes
1 answer
272 views

Why does this regexp — which attempts to match characters between “@” characters — fail?

I need to extract the second field of selected lines in a GEDCOM file. These lines are all of the following format: % grep @ /tmp/XYZ | tail -5 0 @X701@ OBJE 0 @X702@ OBJE 0 @X750@ OBJE 0 @X765@ OBJE ...
user avatar
  • 673
0 votes
0 answers
94 views

feed file list found by grep to scp command

I'm running a local terminal (cygwin-esque), and I'd like to combine two commands into one: xzgrep -l -e 'pattern' * filename * scp user@host 'output of above' /local/path Thanks for any advice :)
user avatar
  • 1
0 votes
0 answers
480 views

grep: /proc/version : Permission Denied

I wanted to run vscode as non root user so I switched to another user by "su - username" and run "code" but it gave an error "grep : /proc/version : permission denied" ...
user avatar
0 votes
1 answer
406 views

Zsh grep with glob * is not working

The same command was working fine with bash git show --pretty="" --name-only HEAD | grep -i .*py zsh: no matches found: .*py Bash git show --pretty="" --name-only HEAD |grep -i ....
user avatar
  • 103
0 votes
2 answers
48 views

Grep Sed with bash

I'm trying to achieve the following using bash and sed where the file containing below strings qa2.test.m.xyz.com 554 1723 21 qa88.test.nj.xyz.com 1723 554 21 443 80 qa2.lite.xyz.com 554 1723 21 ...
user avatar
  • 45
0 votes
1 answer
46 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 ...
user avatar
  • 473
0 votes
1 answer
25 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 ...
user avatar
1 vote
1 answer
228 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 ...
user avatar
  • 304
-1 votes
1 answer
979 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/...
user avatar
  • 223
1 vote
2 answers
272 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 ...
user avatar
  • 23
1 vote
0 answers
130 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 ...
user avatar
  • 11
2 votes
2 answers
1k 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 ...
user avatar

1
2 3 4 5
22