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
0answers
20 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
44 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
32 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
42 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 -> "...
4
votes
3answers
867 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
69 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
13 views

How to grep from the output of grep from the directory?

I have been following an old stack overflow question - old SO post but I dint' get a success. In my example, I am doing a grep recursively on to the directory to find out the word "chown" and ...
0
votes
0answers
9 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
0answers
31 views

Given a large set of IDs, how would one extract information from another tab-separated file both ID-related and closely related data

The ID file is formatted thus: A0A1H3TMV2 Z8X0S9 A0A2M6TTB8 A0A2Q5TOM7 A0A1U4MIN3 X9RTW0 The tab-separated file has the following format: Query ID Neighbor ID A0A1H3TMV2 A0A1H3TMX3 ...
0
votes
2answers
28 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
24 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
42 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
43 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'...
0
votes
1answer
34 views

How do i filter request from a json using curl?

so I recently deployed this Go app on the web https://20200329t202730-dot-ipengine-dev.appspot.com/ and the format that it shows the IP currently is { "ip": "169.254.1.1" } How do I only get the ...
2
votes
1answer
110 views

Using grep to filter folders with numbers

I was trying to list only folders with numbers filtering an ls -1 (option -1 is list one file per line) through grep (I know find can do it too, but the sake of this example I want to stick to grep) ...
0
votes
1answer
83 views

Sort output of grep by file size? (bash)

I want to grep for a certain string, in a certain directory. Then I want to sort the files by size (number of bytes would be fine). The files are .php files, though I don't think other non-php files ...
0
votes
2answers
51 views

Mining plain text

(original title: grep in terms of paragraphs not lines) This question is motived by fzf, which allows me to locate a certain file in my huge file system fuzzily and incrementally, providing a very ...
0
votes
1answer
19 views

Using globs in grep statements

If I grep a whole email address I'm able to turn up a result: grep -ri "us-dbawsnplogging@company.com" * manifest.yaml: email: us-dbawsnplogging@company.com However if I try to use a glob to ...
1
vote
2answers
39 views

how to cat/grep string semicolon delimited

How to cat/grep string into several files semicolon delimited to capture mac address. Example: Folder: /home/acl acl Files: acl1 acl2 string format info acl files: a;mac address;ip address;...
0
votes
1answer
406 views

Remove Strings from files using sed and grep

we are trying to remove a single line of injection code in thousand files of our server of these thing using grep and sed: <script type='text/javascript' src='https://dest.collectfasttracks.com/y....
1
vote
2answers
24 views

How do I sort my output

fdisk -l |grep Disk |grep xvd |awk ' {print $1, $2, $3} ' Output is Disk /dev/xvda: 42.9 Disk /dev/xvdl: 21.5 Disk /dev/xvdm: 21.5 Disk /dev/xvdj: 2147 Disk /dev/xvdk: 8589 Disk /dev/xvdd: 1073 Disk ...
0
votes
1answer
47 views

How to grep a standalone number

So I have a list number: 1 number: 2 number: 11 number: 21 and I'd like to get a line count of how many standalone number 1's there are, but my grep 'number: 1' | wc -l returns positive for the 11 ...
1
vote
1answer
40 views

How to use Grep to find the number of matches from one file to another

I am trying to find the amount of times a match occurs from a list of patterns given in the pattern file, to the target file. Here are example target and pattern files: Target File are bare barely ...
0
votes
1answer
14 views

Does -u reduce the speed of ripgrep?

I have read the man pages and documents online without getting a clear answer. It is stated that using -u with ripgrep will "Reduce the level of smart searching" as well as not searching the ....
0
votes
1answer
91 views

read answer not working on ssh bash -s script

I have some commands to prompt for yes or no answer in my script, but the read answer command (interactive mode) not working, while running the script using ssh bash -s script. ssh user@hostname ...
1
vote
1answer
49 views

How to use pipe into grep to exclude list of files under a second level directory?

I use ripgrep (rg) to list files under a directory. But I want to list files under a second level directory excluding the list of files under one of the directories. Basically if I have ./a/b/c I ...
0
votes
1answer
33 views

Grep match on finding regular expression matches other than known strings

I have a bunch of .sql files and in quite a few of them we use package I wrote called 'carlmann_demo'. Whatever file uses such package will do as follows: -- This line will be present in every file ...
0
votes
1answer
83 views

tail -n1 on latest non-empty line

I wanted to achieve something similar to this grep -v '^$' <myfile-with-blank-lines-at-the-end> | tail -n 1 Basically, I have a file with a unique number, followed by a comma and I want to ...
2
votes
2answers
154 views

How to get the pid of a opened Terminal window in MacOS?

Background I want to obtain the pid of a specific Terminal window. ps -A | grep -w Terminal.app | grep -v grep | awk '{print $1}' However, the above grabs the pid of the entire application and not ...
3
votes
1answer
2k views

Combining find grep and tail

I am trying to find all files that start with a certain name, then go through each file to find lines that contains a string, then only print out the last line of each file that contain the string. ...
0
votes
0answers
19 views

How to parse cec-client output with grep?

I am experimenting with cec-client and would like to simplify its output. I think about grep usage, but don't understand well how it works. Here is sample extract from cec-client output: TRAFFIC: [ ...
0
votes
1answer
44 views

Iteratively find all lines starting with X and move above next line starting with Y

I have a file like this: Lorem ipsum dolor sit amet. Consectetur adipiscing elit. MATCH1 Quis autem vel! Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. MATCH1 Eum iure ...
0
votes
0answers
22 views

Extract emails from files contained in various folders with grep and sort them

I am trying to extract all email address from a specific TLD from files that are located in a big folder and in some sub-folders (maybe this is the issue? nb. I am in the correct directory where the ...
1
vote
1answer
72 views

What regular expression can be used with grep, flag -E, to display lines from a text file with ONLY an odd number of characters?

I am trying to search through a text file using grep and display lines with only an odd number of characters. I need to use the command: grep -E 'some regex' filename.txt but I cannot figure out how ...
2
votes
1answer
31 views

replace keywords in a file by keywords\index{keywords} from a list file

I am trying to produce index entries in a LaTeX file under Linux. I have two files: file1.txt has all the index entries cats\index{cat} dogs\index{dog} elephants\index{elephant} rats\index{rat} The ...
0
votes
1answer
130 views

Using Grep Find and Replace TextWrangler

I hope somebody can help. I need to change a symbol in any line containing - to : but only lines that start with <name> E.G <name>CT Special Forces 2 - Back in the Trenches</name> ...
1
vote
2answers
55 views

Remove specific string from file

output.txt 1.1.1.1:22/ does not support password authentication. [ERROR] target ssh://2.2.2.2:22/ does not support password authentication. [ERROR] target ssh://3.3.3.3 i want to remove string :22/ ...
0
votes
0answers
56 views

How to find attachments in email using bash or PHP

Suppose I have a /mail folder where I collect all email received daily from my server in .eml format. Using normal Linux bash tools is it possible to find in the folder /mail a list of .eml files ...
1
vote
1answer
141 views

find -exec grep {} \; egrep -v string \; # the command chain brakes

I'm playing with find command to see how it behaves and I'm a bit lost. First bit is fine : find . -maxdepth 1 -exec grep -l abc {} \; grep: .: Is a directory ./file2.pdf ./file1 Then I try to ...
0
votes
0answers
47 views

How to grep the process of iTunes in Python scripting

import os, signal def check_kill_process(iTunes): for line in os.popen("ps ax | grep " + iTunes + " | grep -v grep"): fields = line.split() pid = fields[0] os.kill(int(pid)...
0
votes
1answer
33 views

Find all files that don't contain a given string

grep -l "this is a test" will list all files in $pwd that contain the specified string. But grep -vl "this is a test" will list all files including those, because those that contain that string also ...
0
votes
0answers
22 views

MacOS High Sierra - grep, grabbing text between tags

I have a long txt document I'm trying to extract the string in-between various tags. Below is the sample code in bash: #!/bin/bash genre=$(grep -o '(?<=<genre>).*(?=</genre>)' ~/...
1
vote
1answer
90 views

How do I find ‘foo’ on an external USB drive?

Somewhere on my USB drive is a lost file with the string “foo” in it. I want to recover this using terminal on my MacBook Pro. Using sudo as super user I am able to list expected directories with a ...
0
votes
1answer
65 views

Solution for local “database” containing huge text and .SQL files

I have a few hundred gigabytes of text data contained within a single directory tree. This data is comprised of both very large text files and a few MySQL database dumps (which for the most part, of ...
2
votes
2answers
105 views

open files in vim through xargs modification

Using a discovery command utility I can grep the location of some directories, and I need to open containing files. I cannot use find with exec such as this example find . -name "*.txt" -exec vim {} +....
0
votes
1answer
77 views

How to copy grepped files using Find, Grep and Exec in Git Bash

I've looked everywhere for an answer and nothing seems to be working out. In Git Bash, I need to figure out how to take files found with grep and copy them elsewhere. The instructions were to use the ...
0
votes
1answer
386 views

grep command-line search string in all .zip in folder and extract it. in windows 7

am new to grep so please take it easy thanks. here is what i have,i have a folder with 1000 .zip files small sizes and i want to search all them using a string and if it matches then extract only the ...
2
votes
1answer
85 views

Sublime: Find words that are less than 4 characters

In Sublime, how can I use Grep to find words that are less 4 characters? Searching around, I found this answer on how to use Grep to find words that are less 4 characters. It says to enter the ...
1
vote
1answer
57 views

Removing lines containing duplicate regex strings

I am sorry if this has been ask before but unfortunately there are so many questions about this kind of thing and although they are all related so many situations that apply to one instance may not ...

1
2 3 4 5
20