Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [grep]

grep a Unix command-line utility which searches input passed to it for lines matching a regular expression, and prints the results.

0
votes
1answer
16 views

How find line containing string print it + x lines after

I have a log that constantly throws data to the screen. I need to catch a line that contains a certain string, print it and the next 5 lines afterward. It easy to do with a static file like: grep -A 5 ...
1
vote
1answer
21 views

Why do I often receieve `no such process` in response to a process I want to kill?

me@me:~$ ps aux | grep -i firefox me 15413 0.0 0.0 14428 1036 pts/1 S+ 05:46 0:00 grep --color=auto -i firefox me@me:~$ kill 15413 bash: kill: (15413) - No such process Why might this ...
0
votes
1answer
35 views

How to open files which have spaces in filenames with grep?

I would like to search for phrase inside .txt files and with Sublime text open all files which are found. I am using Git Bash for Windows and after various experimenting this is what I have in .bashrc ...
0
votes
1answer
14 views

permission script with stat command trouble awk special character

I want to number of permission directory and write a script for equalizing two different server directory. I have use stat command. command: stat /var/ | grep -i 'Access: (' output: Access: (0755/...
1
vote
1answer
20 views

Ack for files with two phrases on Windows

I want to Ack for files that contain both "foo" AND "bar". I found lots of answers for how to do this on Linux, but not on Windows.
0
votes
1answer
25 views

Exit code of 1 from SSH command

Why would the following return a 1: ssh -tt server_name "sudo grep 'something' /path/to/file || [ $? = 1 ]" The command in double quotes when run directly on server_name returns 0. Why is the ssh ...
0
votes
4answers
69 views

grep uncommented and empty lines in linux

I use below command to filter the file for # and empty lines. But, how can we grep uncommented and blank lines in linux with single grep. [root@localhost ~]# cat test | grep -v ^# | grep -v ^$
0
votes
3answers
48 views

grep or other regexp to get value of output

How to use grep or any other tool to get a specific value in an output In the below output I need to get the value 255.00 in the line with Minimum: 255.00 (1.0000) A pattern like: ...
0
votes
0answers
66 views

Fastest way to search inside a text file?

I'd love to get some advice from people here. I'm trying to make a locally searchable simple/flat database that will just consist of long URLs from my site, and URLs I've shortened with bit.ly. The ...
1
vote
1answer
48 views

How to extract all strings in require('')?

My source files are something like this: abl require('../img/a.png') require('../img/b.png') bla require('../../img/c.png') ble <Image source={require('../img/d.png')} My expected output is: '../...
2
votes
1answer
107 views

Use grep for a long line to get the part of the line

I want to search in a long sentence (more than 1024 letters). I have one text file (test.txt) which has one long sentence, like this: afdafglwqgkjrldjl;ewqje;'k;g;je;;;fdsgalsdkf;akslg;safdas........
0
votes
1answer
36 views

grep -i “^(.).*\1$” sowpods.txt > output.txt

I'm using a scrabble words list I downloaded named "sowpods.txt" and I am trying to use grep to find all of words with these criteria. 7 letter word Starts and ends with the same letter Has the same ...
0
votes
0answers
102 views

Linux grep command getting stuck in infinite loop while doing recurring search

When trying to search for a pattern in files of current and subfolders, the grep command is stuck in an infinite loop. The following illustrates the problem: /results/log/check_log: if ($f1 eq '...
-1
votes
1answer
53 views

find and grep produce different output if executed from script file or command line

I'm using these commands to to search in multiple pdfs, given a file path: >>find /home/ad0x/Documents/Skola/Flervariabel/Tentor -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-...
2
votes
2answers
35 views

replace number with star specific pattern for whole file

In my file I want to replace number to * Example: data[0] ---> data[*] I have data[0] to data[127] and also want to do for the whole file. So how can I do only for number? I tried with command ...
0
votes
1answer
52 views

Windows 10 search: how to preview the part of the file where the word has been found?

When I search the word "computer" on my folder that contains several .docx files, windows list the list of files which contains this word, which is good. But I would like to see more than the list of ...
0
votes
1answer
32 views

How can I “findstr” all links from a source-code of a webpage?

I want to have just the https-Link in a seperate file. How do to that without getting the complete line of the code, just the links?
1
vote
1answer
67 views

Benchmarking bash commands with time and tee

I have a directory containing more than 80GB of simple text file databases that I anticipate needing to grep through often. For this reason, I'm trying to create some tests to compare GNU grep with ...
0
votes
0answers
275 views

What are all of the globs I can use with grep in bash?

Linux and Unix-like shells like bash allow for the use of globs to approximate filenames and make file searching easier. I'm aware of the wildcard glob (*). What other globs exist in bash that I can ...
1
vote
1answer
33 views

mac: concatenate contents of text files across many directories; append directory names to corresponding text file contents

In the following directory structure: directory1 -subdirectoryA ---fileA.txt -subdirectoryB ---fileB.txt subdirectoryC ---fileC.txt I would like to generate a text file containing the following ...
0
votes
2answers
51 views

Can I make one command with “find . -name ”.sv“ | xargs grep -n ”word for finding“ ”

I'm trying to make an alias or something like command with grep and find command in linux. kinda "find . -name ".sv" | xargs grep -n "word for finding" " Can I make one command or aliasing with ...
2
votes
1answer
44 views

Take a file of regexes and return the first match for each in another file

I have two files. a.txt has a list of regexes, separated by newlines. b.txt has lines, some of which match the regexes in a.txt. What I want: A command (grep, probably) that will take the two files, ...
1
vote
3answers
140 views

How can I count how much wood a woodchuck chucks using Microsoft Excel?

TL;DR Is there anything like grep in Excel that can help me count whole-word-only instances (e.g. "wood" but not "woodchuck") (and maybe their variations)? So there's this poem, by mother goose: ...
1
vote
2answers
115 views

Using Grep on txt file to find 7 letter words that start with the same letter

grep -i "^(.).*\1$" sowpods.txt > output.txt I'm using a scrabble words list I downloaded named "sowpods.txt" and I am trying to use grep to find all of the 7 letter words in the file that start ...
3
votes
1answer
44 views

How to get a specific string value from an Apple System profiler SPHardwareDataType

I'm using Bash to rename computers en masse using a part of the serial number, which is pretty easy, but my client has requested that the manufacture year of each machine be appended to the end. ...
2
votes
1answer
96 views

Grep on macOS: find unique occurrences of a capturing group in regular expression

I am on macOS and would like to get into using grep (or a similar tool) to find unique occurrences of a certain pattern in a codebase. For example, for finding all console.somemethod() calls in ...
0
votes
1answer
26 views

How to handle spaces in directory names using grep

I have a directory tree where some of the directories have spaces in the names: top |-- subdir 1 |-- subdir a |-- file1.csv |-- file2.csv |-- subdir b |-- file1.csv ...
1
vote
1answer
108 views

Grep causes entire system to freeze while comparing two files

What I wanted is to compare two files and check if every line in file1 exists in file2. My first try: grep -v -f file2 file1. This resulted in a lot of syntax errors (but didn't freeze anything). I ...
0
votes
1answer
30 views

grep minus number doesn't work

I want to find all files in a directory which contains -2. Using ls | grep "-2" returns usage: grep... Using single quotes instead of double quotes returns the same, and also not using quotes at all,...
0
votes
0answers
25 views

Moving domain name from file using bash

Learning bash at the moment, and I know once I have performed wget cisco.com an index.html file appears. I know by doing cut index.html | cut "/" this provides me with just cisco.com. However, what if ...
-1
votes
1answer
135 views

Parsing JSON with BusyBox tools

I have a POSIX-compatible install script which determines the latest version of some software by grepping info from a json blob retrieved from a software registry: meta=$(wget -qO - https://registry....
0
votes
1answer
33 views

grep regex pattern matches on each line where only all matches appear and print on same line

trying to extract some patterns per line, from a log file. I am trying to extract the first time stamp, and two or three other matches but I want to be able to only print the matches from the lines ...
2
votes
1answer
104 views

Grep regex result not as expected?

Using FreeBSD 11.1: #!/bin/sh if printf 'abcde.fgh' | grep -iEq '^[^][$^*_-]'; then echo "test 1 success" else echo "test 1 fail" fi echo if printf 'abcde.fgh' | grep -iEq '^[^][.$^*_-]'; ...
1
vote
1answer
176 views

How to grep multiple @ types?

I'm using Linux Centos 6-64. How can I change the following command, which only retrieves emails written with @, inside an input folder: grep -E -o -r "[A-Za-z0-9][A-Za-z0-9._%+-]+@[A-Za-z0-9][A-Za-...
0
votes
0answers
322 views

Regex matching in shell script

Here is a snippet from my shell script - regex="<version>([0-9]*)\.([0-9]*)\.([0-9]*)([^<]*)<\/version>.*" #some unrelated lines of code echo $(grep -m 1 "<version>" $1) ...
0
votes
1answer
34 views

How to output a particular word in file, if it is present?

I am making a simple script where i turn true to false if true is present in file or vice versa if false is present in file, details here. Now i want to output, what is the value after change ie if i ...
1
vote
2answers
110 views

Large Data Processing: Removing lines in one text document found in another

I have 2 large text files (~500M, ~15GB ea) That look like this: FileP.txt: test@test.com:testtest test@test.com1:testtest1 test@test.com2:testtest2 test@test.com3:testtest3 test@test.com4:...
1
vote
2answers
31 views

When to use \ in grep search string

I have file content similar to: A+B C+D A+B These are strings. I want to search for the occurrence of A+B. So I write the command as: grep 'A+B' test.txt. However, if I write grep 'A\+B' test.txt I ...
0
votes
1answer
102 views

Logical AND and OR with grep

I want to extract the lines that matches the following logical operation: "AB+CD" AND ("nonAB+nonCD" OR "nonAB+CD"). Which means I want lines with: AB+CD,nonAB+nonCD AB+CD,nonAB+CD AB+CD,nonAB+...
0
votes
3answers
330 views

How to search ocurrence of a word and absence of another using grep

I have a file with content similar to: google.com,9,AB+CD,nonAB+nonCD youtube.com,9,AB+CD,AB+CD facebook.com,20,AB+CD,nonCD The number of columns is not fixed. But the first column is a URL, the ...
0
votes
2answers
705 views

How to start searching from second column using grep command

I have a file contains string like the following: site1.com,Level1.2 site2.com,Level1.1,Level1.0,Level1.2 site3.com,Level1.2 site4.com,Level1.2,Level1.1,Level1.0,Levelv3 siteLevel1.2,Levelv2 Level1.2,...
0
votes
1answer
37 views

find -exec grep 'string' result different from grep -r command's result

Why does this command find /etc -exec grep student {} \; 2>/dev/null show me more results than this command grep -r student /etc 2>/dev/null
0
votes
1answer
59 views

VIM change path to where it was invoked

I really like my vim to change its working dir to the file I'm currently working on. For this I use in my vimrc: autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | lcd %:p:h | endif What I ...
0
votes
2answers
79 views

fdisk -l | grep command with wildcard doesn't show results

Why commands fdisk -l | grep sd? fdisk -l | grep sd?? don't work in this situation and fdisk -l | grep sd[ab] works ?
1
vote
2answers
391 views

How can I output iperf results for only Interval and Bandwidth?

I am trying to get the output from the command iperf -c 10.0.0.1 -t 3600 -i 2 And only need the Interval and bandwidth fields listed for the entire hour of logging. I haven't used grep or awk in ...
0
votes
1answer
73 views

How would I pipe a command to grep to search for a certain string, when part of that string is unknown?

The program I am working on makes use of grep to search a system log for a particular alert, however the an element of the syslog entry I am looking for will pertain specifically to that entry, and ...
0
votes
1answer
453 views

Pass command output as argument in grep

I want to compare two text files for changes line by line. If the files are store locally I know I can do it with grep -Fxvf file1 file2 I have a problem because file 2 is in Hadoop File System. I ...
-1
votes
1answer
200 views

How to grep files in current dir and all subdirs

I know this question has been asked before but the proposed solutions don't work for me. I'm trying to find the string "modelInstance.addObservers" in any file (ideally any file with the .js ending, ...
1
vote
1answer
2k views

does grep regex work differently on mac?

Just trying to figure out basic use of regexes with grep (or egrep) in mac terminal (BSD grep - 2.5.1-FreeBSD). File to examine (pow.txt) contains the lines : kiytytytyty and blob.mkv command ...
1
vote
1answer
785 views

How to search file *contents* (grep/ag/rg) using FZF?

When I run a project-wide (multi-file) search through FZF, the results are flooded with lines whose filepath matches the query, crowding out the more relevant results where the file contents matched. ...