Questions tagged [grep]

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

221 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
1answer
183 views

Search file name within file

Someone put a lot of malicious code onto every single wordpress instance on my server. For the second time. (At least) Every js file has been modified. There is a pattern though, the code always looks ...
3
votes
0answers
28 views

Difference in output of GNU and BSD zgrep

I am using zgrep to search a pattern and print N lines after the matched line from multiple .gz files. In BSD zgrep I see a separator -- after each file: zgrep (BSD grep) 2.5.1-FreeBSD $ zgrep "...
3
votes
2answers
42 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
72 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
178 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
122 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
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
78 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
1answer
71 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
126 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
189 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
108 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
1answer
94 views

Command modification

I'm using the following command to get the highest number of requests per second in a log file and it works well. grep "2017-02-22" "LogFile.log" | cut -c1-20 | uniq -c | sort -n | tail -n1 Now I ...
2
votes
0answers
232 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
585 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
86 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
382 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
1k 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
3answers
1k views

Grep for multiple strings, show number of lines after one of the strings (but not the other)

I would like to search a file for multiple strings and for one particular string, show the 5 lines following it as well. cat file | grep -e 'string1' -e 'string2' works of course, but I would like ...
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
275 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
659 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
99 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
24 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 ...
1
vote
0answers
33 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
32 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
59 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
0answers
89 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 ...
1
vote
1answer
83 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
309 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
193 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
89 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
0answers
83 views

Sqlite: replace a string modelID1/modelID2/modelID3 with name1/name2/name3/

My goal is to read the macOS Photos.app database to find out the paths of the included photos. The album and the parent folder whose name is in the RKFolder table can be determined for each photo. ...
1
vote
1answer
437 views

Multi-line String Pattern Matching, Insertion and Deletion with sed or awk

I'm trying to write a script to automatically update my .ssh/config. Basically it's an ssh management tool that will add an .ssh/config entry for an input computer, user, etc. Question: Are there ...
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
489 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
3k 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
278 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
246 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
591 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
79 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
77 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
42 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
52 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
2k 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
100 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. ...
1
vote
2answers
529 views

Compare 2nd column of the 1st file and 1st column of the 2nd file and print the matched records of the 1st file

I have two files large files: f1.txt: 5020118359 |13ZJ24001218 |20141224|R 5020120475 |13ZJ38000813 |20141204|R 5020127431 |13ZJ38001569 ...