The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [grep]

grep is a command-line tool for searching text patterns in files

218 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
2answers
75 views

Parallel Recursive Grep While Omitting String

Problem I cannot perform a recursive parallel zgrep while also omitting a string from the results. I am zgrepping through about 640GB of compressed firewall logs and almost %30 of the lines have the ...
3
votes
0answers
79 views

Linux permanently hung after running a grep command on “/sys/*” directory

I ran the command: sudo grep -r -i RETP /sys/* On two systems: Oracle Linux 7.5 server (256 GB RAM, 2 Intel® Xeon® Gold 6142 Processor) and on my desktop PC with Ubuntu 18.04 (16 GB RAM, Core i5-...
3
votes
0answers
199 views

How do backreferences slow down regular expression search?

Let's say I have a text file with 20 chars per line like this: wertzuiopasdfghjkl< asdfghjkl<yxcvbnm,.- <yxcvbnm,.-123456789 1234567890QWERTZUIOP QWERTZUIOPASDFGHJKL< and so on ... and ...
3
votes
0answers
126 views

Using ack to effectively search and RStudio project directory

I'm interested in running ack search on a RStudio project directory that mostly contains *.R script files but also some project files and often *.git files. Directory The project folder structure ...
2
votes
3answers
73 views

How to grep data of a new line when capturing a keyword?

I have a file which contains below sample line having a common keyword P00001121 in each line. [H00,P00001121] CHANNEL__OPEN:TCP_ADDRESS='10.32.130.202' TCP_PORT='80'" [H00,P00001121] COMMS_QUEUING:...
2
votes
1answer
69 views

Struggling with output of grep into an array

Please note I'm not a developer but I have requirements where I'm trying to search an SVN repository for files containing certain table names. I have built this script on the basis of many things I ...
2
votes
2answers
41 views

How to select first occurrence from between two patterns including them

What I have: interface GigabitEthernet0/2/1/6.2061 description --> Some description here service-policy input BESTEFFORT-IN service-policy output Egress_30M vrf VPN-s2s ipv4 mtu 1500 ipv4 ...
2
votes
0answers
24 views

why does recursive searching with grep print fewer lines when using \bSTRING\b compared to the -w option?

There are two ways to read all files under the current working directory: grep -rw pip | wc -l grep -r "\bpip\b" | wc -l Assuming 1 and 2 both search the working directory for the whole word "pip", ...
2
votes
1answer
106 views

Grep search for words containing capital letters in Unicode

After some searching, I found a grep command that will find words containing capital letters, and list them without duplicates: grep -hoP "\w*[[:upper:]]+\w*" * | sort -u However, when it comes to ...
2
votes
0answers
111 views

How to improve this 'sed' search & replace command?

How to search and replace recursively through multiple files in a directory, using essential tools installed in mostly any Debian/Ubuntu machine? There are multiple answers in Stack* where to find ...
2
votes
1answer
95 views

Averaging over many rows of data

I have a file of data for 1024 time steps that looks like this: 1 0.240112 0.0610352 1.00659 2 0.240112 0.0610352 1.00659 ... 1024 0.237366 0.0576172 1.00189 I want to do two things -- ...
2
votes
0answers
134 views

What's causing logcheck to take up 100% of CPU load?

So multiple (1 per core) grep processes by user logcheck are taking up 100% of my CPU for a while now. How can I find out what's causing this and how can I fix it without killing the process as I wish ...
2
votes
0answers
199 views

use gff2fasta instead of a bash script to get parts of DNA sequences out of a full genome

EDIT and a solution Because my original question was badly phrased and I was trying to re-invent the wheel I am answering my own question now (maybe it helps someone else): gff2fasta is a tool which ...
2
votes
1answer
118 views

Use sed to keep only parts of a file and reorder it (based on textWrangler grep syntax)

I want to edit a file called trial.fastq with the following format: @NAME123.15.1 15 length=151 GTAGCNTACGGGAGGCAGCAGTGGGGAATTTTCC +NAME123.15.1 15 length=151 AAABB#>>AABDGCEGGGFGGGHHHGGGFHHGHH ...
2
votes
0answers
243 views

Why is output for `grep -o` the same with or without LC_ALL=C?

Why is output for grep -o the same with or without LC_ALL=C? There is a difference for grep with no flags for me as expected but there's no difference for grep -o. Does grep -o always use LC_ALL=C or ...
2
votes
3answers
622 views

Finding a specific character at one to many positions in a file

I am looking for a way to iterate through fixed format text files and looking for a specific character in one to many specific character positions, including the first character position, within any ...
2
votes
2answers
1k views

Read from and append to file at the same time while preserving end-of-line

Conceptually I have an easy task... I have [loosely] structured data in a file: Testing: debug, default CXXFLAGS <100's of additional output lines> Testing: release, default CXXFLAGS <100's ...
2
votes
0answers
88 views

Can I clear an env var during bash completion?

I use bash completion from https://bash-completion.alioth.debian.org/ and some vendor supplied scripts too (eg. https://github.com/git/git/blob/master/contrib/completion/git-completion.bash) I also ...
2
votes
0answers
436 views

accessing old data from syslog

I look after various MySQL DB's which we have recently moved to Linux servers (from Windows). They run fine and everything is good. However, this morning i needed to check the error logs, but these ...
2
votes
0answers
2k views

Grep can't find end of line in DOS format text file?

In Ubuntu I'm working on a C file that was originally created under Windows and then committed to source control. Vim shows the file format is "dos", which I gather just means it has CR/LF line ...
2
votes
1answer
1k views

Filter screenlog with screen command

Pressing Ctrl+A, H, lets me log output of the screen command. However, the output file is too large. Is it possible to apply a grep-like filter so that I can control what gets logged? For example, I ...
2
votes
1answer
282 views

tool in terminal like helm-occur/helm-swoop for terminal?

I don't know whether this is the right place to post this question, but if you are not an Emacs user, I'll explain the basic usage of helm-occur/helm-swoop. I like helm-occur/helm-swoop for Emacs ...
2
votes
0answers
666 views

exit code of grep in trap where the script is launched by upstart service

Recently I encountered a problem in ubuntu upstart and trap in Bash shell. I use ubuntu 12.04. The upstart script(/etc/init/player.conf) is: start on (local-filesystems and runlevel [2345]) stop on ...
2
votes
3answers
118 views

How to copy just certain words from a file into a new file

I have a homework assignment where I have a file that is a large list of words. I have to copy into a new file all the words starting with c and name it cwords. I can see a list of the words by ...
1
vote
1answer
29 views

Grep omits matchs in a paragraph with several occurence of a pattern

I try to find in a paragraph all the expression of the form "word word word word the word word word word". For this, I use the expression grep -E -o '([^ ]+ ){4}the( [^ ]+){5}' But in this example ...
1
vote
4answers
91 views

Filtering CSV dataset to find rows and store them in text file

I'm new to shell commands. I'm kinda struggling with this question based on a CSV dataset fbnews.csv. The CSV dataset looks like this: D,E,F, message, score, A,B,C, ID d,e,f, ...
1
vote
0answers
38 views

2 command nmap in the same line

Hello everyone and thanks for your help I am using this nmap command to obtain host and IP information if port 80 is open. nmap -sV -iL test.txt | grep "Service information:" ; nmap --open -p 80 ...
1
vote
0answers
53 views

How to grep an eternal string coming from STDIN

Using bash i'm trying to grep a string coming from /dev/urandom something like this: tr -cd '[:lower:]' < /dev/urandom | grep -o 'test' Also tried: tr -cd '[:lower:]' < /dev/urandom | grep -o ...
1
vote
0answers
32 views

Continuously display new content of a file that contains a given word

When using less pressing Shift-F takes to the end of the file, and continuously display new contents. Is there any option (with any *nix tool) to continuously display new content which contains a ...
1
vote
0answers
39 views

Which tools can find unicode (UTF-8) text in files containing any form of normalization?

I like to find international text, like "müller", or even chinese text, in files, no matter which unicode representation and case is used. I.e, it should not matter whether the "ü" is stored in NFC ...
1
vote
1answer
33 views

Element comparison between subsequent lines, assigning a value for each null output

I have an output which looks like this: ASCII file I want to pick up the last element from the rows that contain the string "Fe\s2b". But the thing is each occurrence of "H\s\s1\s\s\s\s\s\s4861.33A" ...
1
vote
1answer
86 views

How to get the position of LUKS header by `bgrep`

I tried to get the position of LUKS header: grep -a -b -P --only-matching 'LUKS\xba\xbe' /dev/sdb It is out of memory. Some sugest me use 'bgrep' instead, but I don't how to make it work. bgrep -A ...
1
vote
1answer
91 views

grep: Always show context of N lines

Given a file like asdasd 123 X 456 X 789 asd asd asd asd If I run grep: grep -C3 'X' on the above, I get the following results asdasd 123 X 456 -- 456 X 789 asd asd It appears that grep only ...
1
vote
0answers
397 views

How to tail and grep log file, combine into a single line and pass as argument to another command

Using the following command, I managed to fetch error messages below (it's 3 lines). $ tail -f -n 0 error.log | grep -A2 --line-buffered "Internal server error" ! @79884flo2 - Internal server ...
1
vote
3answers
291 views

How to move a line from a file to the other file on the basis of pattern matching?

I want to move lines from a text file into another text file. Those lines contain a word beginning with an underscore. This word is located on the sixth field of the lines; fields are separated with ...
1
vote
2answers
36 views

sed delete all after the first period followed by numbers inclusive

.bill.sally.foo.bar.1.3.21.3.43.nupkg I want to remove all after the first period (inclusive) followed by numbers so output is: .bill.sally.foo.bar This will be embedded in a python script via ...
1
vote
0answers
94 views

What to grep on result of find function

find . -type d -regextype sed -regex ".*some_pattern.*" -exec sh -c 'grep -Ril "find_it" $0' {} \; What I want to achieve here is to narrow down a number of folders against which grep should be run. ...
1
vote
2answers
48 views

How to find how many values in a column are not present

I've been trying to figure out how to find how many values in a column which are not present i.e. has just a "." For example car.txt Car Colour mpg Year vw_golf ...
1
vote
0answers
523 views

Getting a range of lines between timestamps from /var/log/messages

I want to get all lines between two timestamps from /var/log/messages. I only have start time which I provide to my script as input. The script then should get me all the lines till next day as output....
1
vote
1answer
1k views

How to take blank value in the variable in shell script?

I have taken 2 variables in the grep command for search in the file. User is only putting one and pressing enter on the second variable, its throwing the error. I want to set empty value on the ...
1
vote
3answers
4k views

Check if the particular string is present in a output of shell script using shell command

I have a shell script (test1.sh) which returns the following output Employee ID emp Type return type Admin User us321000034006755 ITdept access Itadminuser I wanted to ...
1
vote
1answer
324 views

How to grep non consecutive patterns

How to grep non consecutive patterns... I run this command. grep -B 1 -A 2 "field-2-value" inputFile.txt |grep -v "field-3" which yields these 4 outputs. [field-1]xxx[/field-1] [field-2]field-...
1
vote
1answer
286 views

Output file content with grep along with directory name

I have something like a tree structure of directories, with some of them having inside a file named "Filename". Inside each of these files, there is some information that I would like to access after ...
1
vote
0answers
634 views

How to grep a bz2 file that is further under a zip folder

How to grep a bz2 file that is further under a zip folder - Ex: I have a work.zip folder inside which i got a couple of XXX.bz2 files which have a pattern i am searching for. I want to avoid unzipping ...
1
vote
0answers
117 views

Emulating git status --ignored in non-repository folder

This might be in essence a duplicate of this question, however the perl script provided did not work in my case as far as I can tell. There are also many questions about finding multiple patterns, but ...
1
vote
0answers
85 views

problems with directing the output of pdfgrep to a file

I'm trying to search multiple pdf files for a pattern using pdfgrep. The command I'm using is pdfgrep --color always <pattern> */*.pdf > outputFile I'm directing the output to a file, ...
1
vote
0answers
44 views

Filter grep result-set by paths containing folder1/folder2 and trim the current folder path from result-set

I have a grep command like below to search for all .xml files containing given string. grep -rl 'product_list_toolbar_pager' --include='*.xml' --color=always Now I am using this command on remote ...
1
vote
1answer
53 views

Match a number with fixed digits while scraping web content

I'm trying to parse a source web pages, trying to find all href similar to this: href='http://example.org/index.php?showtopic=509480 where the number after showtopic= is random (and with 6 fixed ...
1
vote
1answer
3k views

Need to find a response time which takes from 1-3 seconds in Apache logs

I need to find the API response time from an Apache log file. It's like a response time which is takes between 1 to 2 secound or 2 to 3 second. $6 is response time and values comes in microseconds. I ...
1
vote
0answers
102 views

Suppress warning of rbenv versions if no rubies installed

At the moment I'm working on Ansible role that installs ruby with rbenv. In order not to install same ruby version every time I run setup task I have to check that no needed ruby is already installed. ...