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
1answer
47 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 ...
1
vote
2answers
43 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*...
0
votes
1answer
37 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 ...
0
votes
3answers
63 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
2answers
56 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 -...
1
vote
0answers
44 views

grep count mismatch in UNIX [on hold]

I have done the QA testing and got rejected due to a count mismatch. In the source file the trxn word is repeated 6339 times. After processing sed operation on it showing only once though the word is ...
-2
votes
5answers
56 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?
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 ...
-1
votes
1answer
22 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 ...
1
vote
2answers
30 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 ...
0
votes
1answer
45 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 ...
1
vote
2answers
65 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 ...
-1
votes
1answer
31 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
0answers
47 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 ...
-3
votes
1answer
43 views

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

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
1answer
19 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
1answer
27 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. ...
0
votes
1answer
38 views

Grep and Text processing

I have these files; *_NOMm6xR.res *_NOMm5xR.res *_NOMm4xR.res *_NOMm3xR.res *_NOMm2xR.res *35LS05*.res *_NOMm1xR.res *_NOM_SRP.res *35LE50*.res *_NOMp1xR.res *_NOMp2xR.res *_NOMp3xR.res *_NOMp4xR....
0
votes
2answers
51 views

Command in Linux to perform opposite of egrep?

I want to find which of the patterns or words are not present in file. Example : test.txt marco polo charlie anthony john egrep 'marco|polo' test.txt will output marco and polo But I want a ...
1
vote
1answer
69 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 ...
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" ...
2
votes
1answer
40 views

search for single or multiple occurrences of the samestring and edit next line

I have a file that sometimes has one occurrence or multiple occurrences of the same string. I am needing to search for one or more occurrences in the file and go to the next line and keep the values ...
1
vote
3answers
42 views

How can I grep each file in a directory for a keyword and output the keyword and the filename it was found in?

I have a directory with 2000+ text files. I am trying to make a script that: Reads a list of IP addresses from ip.txt Cats each file in the directory Greps each file for the IP address If keyword is ...
-1
votes
1answer
30 views

\back slash charectar and . in grep

I am confused about the backslash character \ and single quotations inside grep. From my understanding it preserves the literal meaning. For example if I do echo 'This is \., it gives me This is \. ...
0
votes
2answers
34 views

grep STOP regex replacing -A option

I'm looking/searching for a way to make grep stop when finding the "|_" specific string after having found the search string. for example, i want to print ONLY the lines starting 2 lines above "...
2
votes
3answers
179 views

How to get single character after space?

How can I obtain below output? I want the first field as it is and a single character after space. echo "Hello world" Hellow If it also has a 3rd field than the beginning character of the 3rd field ...
0
votes
2answers
30 views

Displaying file with grep

I expected grep * filename to print every line of filename since I thought * would match every line of this file. $ cat filename first line second line * $ grep * filename #Why won't this print ...
0
votes
3answers
53 views

awk or grep? - print keyword and following columns

I did some benchmarks and the output is a single file containing multiple results with the following format [blaaa] 1st run T/V N NB P Q Time ========================== 2 3 4 1 2 1....
3
votes
4answers
153 views

How to grep and cut numbers from a file and sum them

I have a log file. For every line with a specific number, I want to sum the last number of those lines. To grep and cut is no problem but I don't know how to sum the numbers. I tried some solutions ...
0
votes
0answers
38 views

How to rearrange a data?

I have Following type of data: each block starting with "Atom An X Y Z", I have 4 rows and 5 columns for each number point. I can arrange somehow for 3 columns and 2 rows with following code. awk '!(...
3
votes
2answers
694 views

Merge two greps into single one

I need to extract an ID from the output of another command. Currently my extracting command looks like: someID=$(command | grep -oP '(?:^Successfully\sbuilt\s)([\da-z]{12}$)' | grep -oP '([a-z\d]{12})...
11
votes
2answers
400 views

Delete all lines which don't have n characters before delimiter

I have a very long text file (from here) which should contain 6 hexadecimal characters then a 'break' (which appears as one character and doesn't seem to show up properly in the code markdown below) ...
0
votes
0answers
39 views

Grep across multilines [duplicate]

I need to grep text with new lines included. Example of code: 1. text==","Timestamp":1554799403148,"text":null}} 2. 3. 2019-04-09 04:43:23.7822|text 4. 5. 2019-04-09 04:43:23.9706|text|GuId:...
0
votes
2answers
32 views

xargs issue with grepped files containing spaces

I have a range of .html files all containing spaces in between. What I need is to locate the file using find in conjunction with grep, and if a match is found, basically I just want xargs to open it ...
2
votes
1answer
55 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 ...
0
votes
1answer
22 views

If $x represent column where x is 1..any what represents rows in bash

Team, i need to know how to operate on value row wise after performing grep. I can operate column wise using $ but how to on row value? my output is cat file.txt | grep -o 'test1[^. ]*' output: ...
1
vote
1answer
41 views

for loops to grep multiple texts from parent file to multiple files in single command

I have 29 fasta files (.fa as extension) named and stored sequences according to their genes. (Example: ribosomal protein L1, ribosomal protein L6P/L9E,...) There were a total of 722 species ...
0
votes
1answer
46 views

awk or grep to get a specific string in shell

I am trying to get only the value of percentage part from this data which is stored in a variable also I want to get only the first percentage value that is present in the output. <map id="...
-1
votes
2answers
73 views

Extracting Text between Two Strings in a Huge Ordered Text File

We have a huge text file containing millions of ordered timestamped observations and given the start point and the end point, we need a fast method to extract the observations in that period. For ...
0
votes
2answers
60 views

How to count many lines have the same number in two columns?

I need to compare the numbers in two columns and count how many lines have the same value in both columns. For example: 17 19 17 17 17 18 19 19 25 22 34 34 Expected output: 3 I can't ...
-2
votes
1answer
41 views

grep to find lines that contain six or more non-vowel characters in a row

Using grep and regular expressions, I need to output all lines in a file that contain at least six characters in a row that aren't vowels. This includes any consonants, punctuation, numbers, etc.
-1
votes
0answers
97 views

Building a script to find a file if exists and grep for a string

Following K7AAY and 0xSheepdog advice I'll rephrase. I need to create a bash script where it will grep a log file that is generated daily when a file is sent in a range of time of the day. The ...
0
votes
1answer
22 views

Extract lines from files containing a string but not another in that same line

I am using grep within a script to obtain a list of filenames of the files that contain a certain string. The basic instruction would be this one within a do loop: if grep -q "$str" Inputs/inp$n; ...
5
votes
1answer
538 views

Why do I get “Binary file matches” with grep -I?

In the following example, grep behaves strangely: it's supplied with -I option, which, according to man page, should make grep ignore binary files (similarly to --binary-files=without-match), but I ...
4
votes
3answers
84 views

Shell script to extract data from a list of files and saving it as a csv

I'm on CentOS. I have a list of files that I want to read, extract data from them and organize it as a csv file. The log files text format is: ... {"name":"test-api","hostname":"ci47","pid":3202,"...
0
votes
0answers
38 views

Count values of dict-like object in multiple files

I have three txt files that have this format: File 1: { "username1":10, "username2":11, "username3":100, } File 2: { "username1":4, "username5":15, "username6":25, } File 3: { "username1":6, "...
0
votes
3answers
39 views

“grep -Rl” results as vi arguments with proper space support

I am trying to do something like vi `grep -Rl 'keyword'` But I want to support spaces in the file names. vi "`grep -Rl 'keyword'`" Does not do what I need, it turns the grep output in a single ...
2
votes
2answers
28 views

Check which strings from list never appear in recursive search of directoy

I have a list of strings stringList, where I want to recursively search a directory and find all of the strings in stringList that did not appear in any search result. Right now, I have cat ...
0
votes
1answer
20 views

Find specific folder path in s3 bucket

I'm searching a folder in s3 bucket using this command aws s3 ls s3://bucketname/dir1/dir2/dir3 --recursive | grep -i 'dir3' It's getting results like dir1/dir2/dir3/1/aaa.txt dir1/dir2/dir3/1/bbb....
-1
votes
0answers
38 views

grep and tail multiple files

I have multiple calculations running in various folders and sub folders and would like to see the relevant output for all files with the word 'CONVERGED' in the last 200 lines of the file. The word ...