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
1 vote
2 answers
134 views

How to search for all text lines that start with a tab character?

I need to find all lines in a text file that start with a tab character. I tried this command: findstr /B /R "\t" test.txt But it doesn't print any lines. I also tried with grep.exe (taken ...
Mercalli's user avatar
  • 209
-1 votes
1 answer
36 views

grep output to file does not work - ping www.google.com |grep -v "time=1." >>ping.log

ping www.google.com |grep -v "time=1." >>ping.log Nothing is appended to the logfile, without the redirection the command works fine. What am I doing wrong ?
Gunnar's user avatar
  • 1
6 votes
2 answers
467 views

Maven - ignore ANSI color escaping chars in grep search

I find that sometimes, ANSI escaping chars in mvn output prevents me to do this search with grep: mvn | grep -P "\[INFO\]" I have to use "\[.*INFO.*\]" to get results. How to ...
WesternGun's user avatar
0 votes
1 answer
47 views

Using grep to search for files with a specific extension [duplicate]

I'm trying to recursively look for C Sharp files containing specific text using a bash prompt on Windows Subsystem for Linux. If I type grep -l -i -r "public virtual List<" /mnt/c/mycode/*...
Eric's user avatar
  • 1,203
4 votes
3 answers
694 views

How to check if a command is running currently? [duplicate]

I want to check if a command is running with the following if clause, but it's always true, whether command actually is running or not: if [ $"(ps aux | grep curl)" ]; then echo is; else ...
Saeed's user avatar
  • 387
0 votes
1 answer
43 views

Does Microsoft word have wildcards for return (\r) & new line (\n) like Grep or Regex do?

I frequently want to replace multiple consecutive return characters in written documents with a single return character and to use paragraph space (space after) to do the formatting. Sometimes there ...
wide_eyed_pupil's user avatar
1 vote
1 answer
110 views

BBEDIT multi-file search : multiple find&eplace queries simultaneously?

In another thread grep search got the proper use right for the OR argument in a grep search in BBEDIT and so was wondering whether this can be expanded as following : is it possible to have a given ...
istackoverflow's user avatar
0 votes
2 answers
173 views

Replace between brackets content sublime & regex

I've actually got lines like this: [Sat Dec 31 18:24:18.700 2022] 0.017 sec 0.017 sec [all/2/rel 37 (0,700) @groupparentid] [post]keyword How can I delete the whole line starting with bracket [ and ...
Nass's user avatar
  • 1
0 votes
1 answer
27 views

How to highlight text using color in output if in a certain temp range

I am outputting the HDD temps of my system to a text file on a local webserver that I can check every once in a while to monitor hdd temps when the system is under load. I was wondering if there is a ...
Sabat's user avatar
  • 1
0 votes
0 answers
90 views

bash loop to create m3u file with sed awk grep

I am trying to auto create m3u file for my IPTV software with the help of sed/awk or grep command,but don't have much experience in this. expert help required to do this. working on Windows-10 PC ...
Rizwan.A's user avatar
3 votes
1 answer
99 views

Getting average CPU frequency

Which command should I use to get the average CPU frequency? inxi -C requires sudo. I looked on the internet, but could not find a non-sudo command that would display what I want. I don't mind ...
enrico223's user avatar
0 votes
2 answers
84 views

How to combine tee, sed and grep?

I have a command after which I place | tee >(sed $'s/\033[[][^A-Za-z]*[A-Za-z]//g' >> ~user/filepath/file.txt) The tee is redirected to sed $'s/\033[[][^A-Za-z]*[A-Za-z]//g' which removes the ...
qwerty's user avatar
  • 11
0 votes
1 answer
60 views

gnu grep -r -R -recursive not working on Windows 11

I submitted the following commands through the cmd window on a Windows 11 machine: grep -r --include=*.c "return" grep -r --include="*.c" return grep --recursive --include=*.c ...
D. Scruggs's user avatar
0 votes
1 answer
44 views

Grepping an specific command give me an old grep output

I need some help, wasn't able to find a solution... I've made a script to run xfs_growfs and pipe its output to know only if the it found no difference is disk size and gave me an "data size ...
Erick Jorge Louis Mendes Nolet's user avatar
0 votes
1 answer
29 views

Linux - Find string and then end of section

I have an XMLTV file. I need to get all of the programme sections for a specific channel. An example snippet: <programme start="2023031305000 -0400" end="2023031305300 -0400&...
Dan Marcoux's user avatar
15 votes
1 answer
2k views

Why does my "grep" stop filtering a non-ASCII file it thinks is "binary"?

I'm working with a Windows-10 computer, using a WSL. I'm investigating a logfile, produced by NLog in a C# application. I'm expecting log entries to appear everywhere throughout the file, but I see ...
Dominique's user avatar
  • 1,931
0 votes
1 answer
27 views

In some of my VMs grep does not show color. Is there any shorter switch for `grep --color`?

I have to ssh login to so many VMs / containers. In some of my VMs grep does not show color. Is there any grep default settings? Is there any shorter version of grep --color switch?
Allan Xu's user avatar
  • 639
1 vote
1 answer
112 views

Waiting until a string appears in a log file

I have a log file that text is appended to during the program run. I want to know when a specific string was appended to the end of the file. All the solutions given here: Monitoring a file until a ...
Codo's user avatar
  • 13
0 votes
1 answer
61 views

Grep -f seems to return every file in a directory

I am using grep -f to search through a directory for files that match the strings in the file I provide. Below is the command I am using $find $(pwd) -type f |grep -f list.txt >result.txt I am ...
program12323's user avatar
1 vote
1 answer
39 views

How do I correctly execute 'vim $(grep -rli pattern | sed 's/\(.*\)/"&"/')' in bash?

I am trying to edit files that contain text matching a regular expression with vim and use the following command in bash to do that: vim $(grep -rli pattern | sed 's/\(.*\)/"&"/') I ...
René Nyffenegger's user avatar
1 vote
1 answer
50 views

Can I replicate the `strings` command using `grep`?

I often use a Windows Git Bash environment, which doesn't contain the strings command. Is is it possible to use a tool like grep to output all the strings of ASCII or printable characters above a ...
mwfearnley's user avatar
  • 7,112
0 votes
1 answer
33 views

How to grab filter the numbers of results

I use grep -E '^[ 0-9]{6}$' to grab strings of 5 digits (numbers or space) in files It returns: 71 051 17 293 017299 862610 But is it possible to extract only the 2 first occurrences? If possible ...
user avatar
0 votes
0 answers
45 views

grep with -P (=PCRE) and ext regex pattern (?(cond)yes-pat) does output line despite non-match, what do I wrong?

I am using grep version grep (GMU grep) 3.0 and I have tried following test code with these results: echo "ab" | grep -P '(?<=a)b'; WE_retcod=$? yields ab (b is colored) retcode is 0 ok ...
Anton Wessel's user avatar
0 votes
0 answers
184 views

Windows CMD - Is there any way of getting the plain text from a compiled CHM help file and/or a PDF?

I have a build chain based on Windows batch and Python files. As part of the build, there are variables that are determined and are then communicated to the application CHM help compiler and PDF ...
rossmcm's user avatar
  • 1,556
0 votes
0 answers
120 views

Redirect pipe contains quotation marks to a variable in Windows batch file

I am trying to get the number of substrings "id" in a file and save to a file I am trying to do it this way: for /F %N in ('"C:\Program Files (x86)\GnuWin32\bin\grep.exe" -o "...
JackHuman's user avatar
4 votes
3 answers
950 views

Copying a path in the terminal with the keyboard

I often find that when using the command line, I need to copy a path that appears in the output of the last command. For example I might use find . | grep like this: [user@localhost /tmp]$ find . | ...
Raffi's user avatar
  • 163
5 votes
1 answer
676 views

How to print and pipe log file at the same time?

I use this to check the log lines of a log file until the occurrence of a specific event (taken from this answer to Monitoring a file until a string is found): (tail -f -n 0 test.log &) | grep -q '...
not2savvy's user avatar
  • 521
0 votes
0 answers
21 views

mingw grep does not find matched results

grep -rn "bg.tool" "pom.xml" does not find any result in pom.xml. However, many pom.xml in the current directory or its subdirectories contain that string. Is it a MINGW thing, or ...
Tiina's user avatar
  • 2,860
0 votes
1 answer
210 views

ext2fs and e2p packages are not found

I'm installing ext4magic on CentOS 7. When I run ./configure it stops at a certain point returning an error message. configure error: You must install the develop packages "ext2fs, blkid, e2p, ...
David Buik's user avatar
2 votes
1 answer
131 views

Is there a way to Grep multiple HTML pages on a domain without downloading the files?

I essentially want to Ctrl+F multiple sites in a browser. I have a range of URLs on a domain https://exampleblog.com/posts/{1-50} I want to grep all of the pages under /posts/ at once. They are each ...
dcannistraro's user avatar
1 vote
1 answer
261 views

grep search count occurrences in number of files in recursive folder tree

Say I have 1000 files in multiple recursive folders and say the string 'testing' is in 600 files and total number of mention of 'testing' within those 600 files is 750 times. Then - I need something ...
Rajib Paul's user avatar
0 votes
0 answers
674 views

egrep warning: egrep is obsolescent; using egrep -E

could someone help me with the problem I had when installing and starting xampp, it shows me this error. (Arch-Linux) sudo /opt/lampp/lampp start XAMPP: Starting Apache...egrep: warning: egrep is ...
LEO JARABA PEREZ's user avatar
0 votes
3 answers
102 views

Get a valid path with random directory name from a text file

How to to get the valid path from a string? For example I have the following text in file.txt that will always generate with a random path using the following patern: Some error occurred. rerun the ...
Kalib Zen's user avatar
  • 103
0 votes
1 answer
342 views

How do I change the order in which grep looks for pattern in files by filename

I have a directory with a bunch of files with numerical filenames like this: 1 - filename 2 - filename 3 - filename etc... They don't have leading zeroes, so if I do something like grep -oha "...
Mihail's user avatar
  • 1
0 votes
1 answer
42 views

Select group of words

I am trying to capture all the words which are bold including the colon. I am using the following code which is not working. (1)This is heading: This is description of heading; This is another: This ...
Shahid's user avatar
  • 53
0 votes
0 answers
50 views

How to move all old files from Downloads to the trash with one or more terminal commands in macos?

I already found the command with which I can select all the files and directories that I do not want to send to trash. That command looks like this: find ~/Downloads -newerat "2 months ago" -...
Evert's user avatar
  • 131
-1 votes
3 answers
734 views

sed or grep command to extract all lines that match a particular date and time range

2022-09-08T08:55:10+02:00 2022-09-08T19:55:16+02:00 200 200 76 0GET /v1/heartbeat/tcanalytics HTTP/1.1 2022-09-08T23:55:17+02:00 200 200 POST /...
Archana Malakalapalli's user avatar
0 votes
1 answer
221 views

how to grep only text preceded by several ‘=’ characters

I want to grep only text preceded by several ‘=’ characters. tried this but doesn't work cat sometext.txt | grep \= and cat sometext.txt | grep ^--[[:alpha:]]\{2,\}=[^=]\+$ (where sometext.txt is ...
arnle's user avatar
  • 101
1 vote
2 answers
55 views

Reverse Quotes in a document using Regex

I have a document which contains lots of sentences in quotes. Issue is that some of them are properly quoted and some of them have reverse quotes, meaning the opening quotes are at the end of the ...
Shahid's user avatar
  • 53
0 votes
1 answer
551 views

Replace strings from text file with csv values

I've got a txt file (template.txt) with stuff like: Hostname from Client: !hostname . OS !windowsversion and a CSV-Export from many clients: !hostname, !windowsversion exampleName, Windows10-Pro I'm ...
taxyee's user avatar
  • 1
2 votes
0 answers
284 views

Why would the windows implementation of grep command here, from cmd, give an error message of trailing backslash?

Why would the windows implementation of grep command here, and from cmd, give an error message of trailing backslash? C:\Users\User>where grep c:\cygwin\bin\grep.exe C:\Users\User>c:\cygwin\...
barlop's user avatar
  • 23.2k
0 votes
2 answers
202 views

In Windows cmd, does grep use GetCommandLine(), and findstr use argv?

In Windows cmd, does grep use GetCommandLine(), and findstr use argv? This is the grep i'm using C:\>where grep c:\cygwin\bin\grep.exe C:\>c:\cygwin\bin\grep.exe --version grep (GNU grep) 3.7 ...
barlop's user avatar
  • 23.2k
1 vote
1 answer
135 views

what is the difference between 'grep -n ' \.*' test.txt' and grep -n '\.*' test.txt

When I run grep -n ' \.*' test.txt , I get: 1:Hello! This is a Unix \ Linux test text file. 2:It is being used to check multiple grep commands. 3:It is very useful. 4:.Below are some tabular ...
Venus's user avatar
  • 11
0 votes
1 answer
237 views

Capture process output with sed, capture block of text and then filter inside it

There is some stdout that I would like to filter with sed but I don't know how. The stdout example would be: . . . Model a. # This should be captured . . . Metrics results: # This ...
eljiwo's user avatar
  • 103
0 votes
1 answer
574 views

Displaying users and their home directory but NOT WITH awk

I have seen similar questions and I actually found the solution using awk command, but I'm not allowed to use it in my homework. so I want to know if there is another way of displaying all the users ...
Saad Out03's user avatar
0 votes
2 answers
230 views

remove duplicated lines taking into account only two columns

I have a file that has some duplicated lines if I take into account only the two first columns. For example 2 2 7 7 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 3 3 7 7 4 4 9 9 4 4 2 2 In this example, I have ...
Eric González's user avatar
0 votes
1 answer
45 views

Insert new line if file contain string

I need to insert 'import packagename' to the line after imports. In files which contains the specific word. What I try: find iOS/Chat \ -type f \ -name "*.swift" \ -exec gsed -e "/...
Bimawa's user avatar
  • 101
0 votes
2 answers
2k views

How to group and count all lines in a file that contain specific string

I want to filter all lines from a file that contain mySearchString and after that group them together and count them. Example find all lines that contain 9791 AB-9791___Foo AB-9791___Foo DE-9791___Bar ...
surfmuggle's user avatar
0 votes
1 answer
663 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 ...
automatix's user avatar
  • 1,369
1 vote
0 answers
545 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 ...
John's user avatar
  • 11

1
2 3 4 5
23