Stack Exchange Network

Stack Exchange network consists of 175 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 is a command-line tool for searching text patterns in files

0
votes
3answers
22 views

extract lines containing patterns file and save them in different files grep, sed, awk, print

I have this file - . ID = tom_fa_10005086 - 0 Parent = tom_fa_10005086 - 0 Parent = tom_fa_10005086 - 2 Parent = tom_fa_10005086 - 1 Parent = tom_fa_10005086 - 0 ...
1
vote
1answer
25 views

Convert json file to a “key-path” with the resulting value at the end of each “key-path”

I have a large and relatively complex json configuration file that I want to search for keys and/or values using simple tools like "grep". When I 'grep' the file I would like to have in the output ...
-1
votes
3answers
75 views

find the word that appears the most at the beginning of a line from entire paragraph

I have a paragraph and I want to know which word appears the most at the beginning of a line from all paragraph for example: paragraph: Hello my name is X Nice to meet you Hello my name is Y so ...
0
votes
2answers
23 views

Pipe and filter bash outputs in realtime

I am running some commands in bash (basically some ffmpeg commands), that I'm using grep and awk to filter out the results. The command takes some time and continously outputs some results as it ...
1
vote
1answer
38 views

Grep/sed/awk solution to excludes lines between two search keywords

I see there are ways to print lines between two search patterns, as explained here How to grep lines between start and end pattern? sed -n '/aaa/,/cdn/p' file awk '/test1/,/test2/' I need negation ...
1
vote
2answers
877 views

Grep --line-buffered, can I search the same buffer with the results of the first grep?

I'm searching a log file in the following format <date> <connection from: ip> <new connection ID> <info> <date> <connection ID> <info> I'm using the ...
-1
votes
1answer
31 views

Variations of the Same Command Return Same/Similar Result

I'm working on a public server, which offers games designed to teach people Linux and ethical hacking skills. The goal of each level (so far) has been to find the ssh password to the following level ...
0
votes
2answers
27 views

finding files of a particular pattern

I want to find names of the file having abc in its name. For example: Dozain123.ctabcln_WbLogReq.log' Dozain123.ctabcln_WbLogReq123.log Dozain123.ctabcln_WbLogReq456.log Dozain123....
1
vote
2answers
2k views

parse HTML in Bash (when grep just isn't enough)

This is driving me insane, as I'm sure there must be some program doing the job but I just can't find it. To be noted, I'd be on ARM/Raspberry so unfortunately Xidel is not an option here, unless ...
0
votes
2answers
41 views

Don't print the same string again if it was found between two files

I'm looking for the string SUCCESS into the file_1 & file_2 which in this case looks for the string and prints it based on whether its there on only file_1 or on both file_1 and file_2 while I'm ...
0
votes
1answer
60 views

Complex string replace - multiple files, multiple different strings, must include certain text

I have a number of XML files (Atlassian Confluence space exports FYI), that I need to parse through to replace certain strings, as long as the line begins with a set string. Here is an example of a ...
1
vote
2answers
61 views

Grep complete name including dot in pattern

I want to grep the complete word with dot. Like I have file test.txt Data in file: Abc ABC.xyz abc ABC.xyz Def DEF.mno def DEF.mno When I am using grep -o I am getting below output grep -o "\w*...
3
votes
3answers
79 views

Extract lines that have two or more dots

I need to extract (or count) the lines (in a file) that have two or more dots. The lines should not start with dot (it’s OK if they end with a dot), and there must not be two dots in a row (i.e., the ...
19
votes
15answers
38k views

'ls -1' : how to list filenames without extension

ls -1 lists my elements like so: foo.png bar.png foobar.png ... I want it listed without the .png like so: foo bar foobar ... (the dir only contains .png files) Can somebody tell me how to use ...
-1
votes
1answer
55 views

How can i terminate 'find' after the first match?

I am using find in a while loop. it takes a list of ips in ip.txt, searches for the ip in a directory of files and then writes the name of the file that each IP was found in to a file called results....
1
vote
2answers
27 views

Using grep to omit values given in a text file [duplicate]

Omit.txt 001 006 008 0016 Filetogrepfrom.txt 001 006 007 008 0016 00546 008 0031 00 0021 0016 I want to do cat filetogrepfrom.txt | grep -a 00 | grep -v {lines from omit.txt}
2
votes
2answers
85 views

How to grep all lines from one file in specific column in multiple other files?

I have one file: combined.txt like this: GO_GLUTAMINE_FAMILY_AMINO_ACID_METABOLIC_PROCESS REACTOME_APC_CDC20_MEDIATED_DEGRADATION_OF_NEK2A LEE_METASTASIS_AND_RNA_PROCESSING_UP RB_DN.V1_UP ...
0
votes
4answers
80 views

Removing lines whose first column is duplicated

I have a file where strings are separated by a special string (not a comma or delimiter) e.g. <vvv>. I want to check if all strings in the first field are unique. If duplicate rows for the same ...
0
votes
0answers
65 views

grep count mismatch in UNIX [closed]

while counting the number of records between source and modified using grep command difference showed. In the source file the trxn word is repeated 6339 times. After processing sed operation on it ...
1
vote
2answers
39 views

grep from list of keywords

Over the past couple of days I've been trying to dig through directories of files to report on files containing key words. Through the help of other users showing me the correct syntax for grep and ...
0
votes
1answer
29 views

How to capture two regex

In this command, I want to extract strings that are like *.com or *.net, where * is not a dot. I wrote this: grep -P -E '^[^.]+\.com$ |^[^.]+\.net$' example.csv I get this error: grep: conflicting ...
0
votes
1answer
51 views

Grep not understanding whitespace delimiter?

In the following example: apt-file search apache2.conf | grep -E "apache2.conf\b" Output: apache2: /etc/apache2/apache2.conf apache2-doc: /usr/share/doc/apache2-doc/examples/apache2/apache2.conf.gz ...
10
votes
3answers
4k views

How to grep for unicode � in a bash script

if grep -q "�" out.txt then echo "working" else cat out.txt fi Basically, if the file "out.txt" contains "�" anywhere in the file I would like it to echo "working" AND if the ...
-1
votes
1answer
64 views

Customize grep option according the output of URL

I want to be find the updated Kernel version using curl command and local kernel version using grep and uname -r commands. curl -s https://api.linode.com/v4/linode/kernels/linode/latest-64bit | grep "...
1
vote
3answers
157 views

Grepping for PCI ID - String like this [10de:1c81]

I'm trying to script setup for PCI GPU Passthrough w/ KVM on Linux. You need to find the pci device ID via the following, root@kvmatrix:~# lspci -nn | grep VGA | grep NVIDIA 01:00.0 VGA compatible ...
0
votes
1answer
39 views

Formating grep output

I have website on my hard drive that I need to locate keywords within the HTML files, then output to an html file, listing each find on a new line. Currently i'm useing the line below, but the output ...
4
votes
5answers
2k views

Is grep documentation about ignoring case wrong, since it doesn't ignore case in filenames?

The man page for grep reads -i, --ignore-case Ignore case distinctions in both the PATTERN and the input files.  (-i is specified by POSIX.) However, if I change case on a filename, it won't ...
0
votes
2answers
71 views

Grep in file with whole cat output

I search/try to write short script (for if loop) to do grep in file by whole cat output. Already I tried #!/bin/bash find -name 'xmlrpc.php' -execdir bash -c ' if [ -e ".htaccess" ] ; then if grep -...
-2
votes
5answers
63 views

Print filenames containing multiple strings

Let's say I have multiple files with .ext extension containing multiple lines. I need to print filenames containing all 3 keywords: kwd1, kwd2, and kwd3. How do I do it?
1
vote
4answers
2k views

grep seems to ignore --include

man grep says grep [OPTIONS] PATTERN [FILE...] . . . --include=GLOB Search only files whose base name matches GLOB (using wildcard matching as described under --exclude). ...
0
votes
1answer
46 views

Understanding grep -oP … In a script

I'm writting a litlle bash script for debian. I want to find the 3th octet of my IPv4 and push it into "ip1" variable, and push the final octet in "ip2" variable. After some researches I found a ...
3
votes
2answers
453 views

Looking for duplicate instances of a tag in a file

Mutliple snippets of code exist in a file similar to the following: <blah>Spread the peanut butter <ramout assot="f0123_fun10" bapel="2 or 6"/> on good looking bread <ramout assot="...
1
vote
2answers
35 views

Regular expressions in grep

The man page for grep reads (emphasis mine) REGULAR EXPRESSIONS A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to ...
118
votes
14answers
87k views

How can I grep in PDF files?

Is there a way to search pdf files using the power of grep, without converting to text first in Ubuntu?
-2
votes
0answers
61 views

Need way to grep through files for malware

I am running into a lot of issues with some files being infected, however, I figured they are very similar code inside and I was thinking about grep-ing through files to find this snip of code. The ...
1
vote
3answers
93 views

How to grep 7 lines after match and replace text?

I'm trying grep 7 lines after match and replace a context in those 7 lines and save it in the same file. For Example: <IfModule prefork.c> StartServers 8 MinSpareServers 5 ...
0
votes
2answers
72 views

find a pair of words that appear the most of the times together

I have 10 text files, in each file i have a chapter from a book, i want to find the pair of words that appear the most of the time together in a line i.e: chapter1: hello world good boy green sun ...
-3
votes
1answer
43 views

Scripting School Assignment renaming files without extension .old to have .old [closed]

My goal is to change the file extension of files that do not have the .old extension to contain it after the script. Another goal is for me to do it with a for loop piped with grep -v to check match ...
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
30 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" ...
0
votes
2answers
821 views

Search the value from a dynamic file and pass to a variable in HTML [closed]

I have the following file below with the format and I want to pass the value to HTML BE64533-A0E1-4F98-A91F-02C1D0 column=ABC_Received:ABC_Structure_Type, timestamp=1439978656596, **value=ASCII** ...
4
votes
2answers
76 views

Invert matching lines, NUL-separated

I’m writing something that deals with file matches, and I need an inversion operation. I have a list of files (e.g. from find . -type f -print0 | sort -z >lst), and a list of matches (e.g. from ...
1
vote
1answer
274 views

Problem with grep on multiple files and not getting desired output

I am using the below command on a file to extract few lines based on chr# ( different chromosome numbers). This is just a single file am working on. i have 8 such files and for each file I have to do ...
1
vote
1answer
22 views

Multiple input for grep

Is it possible to use more than one input on Unix grep? Here is what I'm trying to do: pip freeze list all installed python packages, but unfortunately also list it's dependencies cat requirements/...
0
votes
3answers
562 views

Grep partial string only

I got a file. This file contains strings like sdnfasdnbfas;jdfnba;ldjfnb;asdf[MESG: I NEED THIS: 1] adsfasdfasdfasdfasdf sdnfasdnbfas;jdfnba;ldjfnb;asdf[MESG: I NEED THIS: 2] adsfasdfasdfasdfasdf ...
557
votes
13answers
1.3m views

How do I grep for multiple patterns with pattern having a pipe character?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
0
votes
1answer
100 views

how to count number of files in a sub-folder having a specific pattern?

I have installed ubuntu as part a college course and I would like to familiarise further with the command line. I have ton's of text files which I would like to search for specific phrase but I don't ...
0
votes
1answer
29 views

Get Lines between pattern 1 and pattern2 which may accure multiple times

I try to print out the lines between two different patterns(including the patterns) which may accure multiple times in a file. The second pattern may accure besides the startpattern-endpattern-rhytm. ...
1
vote
2answers
641 views

Extracting text blocks based on grep output

I'm currently working with a text file that contains the following text blocks: -------------------------------------- Beginning of block Text Random Text keywordA Text End of block ------------------...
0
votes
3answers
5k views

Ignore lines containing a capital letter

Why does the following command still return some lines containing a capital letter? aspell dump master | grep ozz | grep -v '[^A-Z]'