Questions tagged [grep]

For questions pertaining to grep, a command-line tool for searching text patterns in files. Use this tag for questions about grep itself or questions about issues arising from using the grep command-line tool.

Filter by
Sorted by
Tagged with
0
votes
0answers
26 views

How to search for the functions that call specific function in a codebase?

I want to search for patterns in a code similar to this: function foo() { bar(); } Closest I could get was grep -l '^[ \t]*function foo' | xargs grep -l bar and then checking those files ...
2
votes
3answers
310 views

How to grep full words between spaces

For example, I have a string like this: 1341 5415 fdad. Command grep -E "(^|\s)[1-9]{1,5}($|\s)" -o will give only 1341, but I want to get 1341 and 5415. How can I do this?
0
votes
2answers
22 views

Why grepping between two tags does not work with option -z? How to fix?

This case: $ cat t01.txt xxxyyyzzz $ cat t01.txt | grep -Po '(?<=xxx).*(?=zzz)' results in: yyy which is expected. However, this case: $ cat t02.txt xxx yyy zzz $ cat t02.txt | grep -Pzo '(?<...
1
vote
1answer
46 views

Why does `grep` seem to give slightly different results with a plain `ls` command? [duplicate]

I have a directory with some files - mkdir _tmpmm touch a1 b2 c3 d4 ls # a1 b2 c3 d4 When I grep for a on the output of ls, I see only the file a1 - although the ls output is showing 4 files on ...
-2
votes
2answers
86 views

Reading from structured file to invoke a grep on matches

Have got a log file with a structured list of filenames with the first file being identified by the descriptor File:, with the remaining files being on a separate line with a + character at the ...
2
votes
2answers
76 views

File matches with structured information

The following grep command that returns the files that contain the string ptrn. The sed command skips files using a step stored in stp. grep -rl "${isufx[@]}" -e "$ptrn" -- "$...
0
votes
1answer
17 views

How to search over symbolink links for the existence of a file?

As a follow up on this question, I am trying to determine which command/sequence of commands can give me which of the network interfaces listed under /sys/class/net is the wireless one - by searching ...
0
votes
2answers
32 views

Extract function string before function name with regex

I want a regex that would search for something like: package_name.some_function_name.foo() that would be part of a line and would and extract the some_function_namebut it should be able to work ...
3
votes
2answers
102 views

How to search for a string in a very large file with very long lines?

It turns out I was accidentally using grep wrong yesterday. I just checked my bash history and saw what I was executing: grep search-string-here -f large-file-with-long-lines.txt And that was what ...
0
votes
3answers
49 views

How to find a string occuring between two other strings on other lines

How would I search for a certain string that is preceded by another string, in most cases several lines up, and followed by another string, i.e. contained in a certain environment? \begin{quote} %...
0
votes
2answers
50 views

Replace string with another one and vice versa

I have a folder structure like below: a/b/sample.txt c/d/e/sample1.txt Both sample and sample file contains the sentence My name is Debojyoti e/f/sample2.txt g/h/i/sample3.txt Both sample2 and ...
0
votes
2answers
15 views

Grep is not retrieving string with space

I have a series of headings in a file that have names like this: grep ">scaffold_3" DM_v6.1_unanchoredScaffolds.fasta >scaffold_3 >scaffold_303 >scaffold_31 >scaffold_34 >...
1
vote
6answers
288 views

print lines between 1st occurence of 1st pattern to last occurence of 2nd pattern with AWK

I have a datafile, with dates in 2nd column # cat datafile -;20210106;-;-;-; -;20210112;-;-;-; -;20210112;-;-;-; -;20210112;-;-;-; ... -;20210217;-;-;-; -;20210217;-;-;-; -;20210217;-;-;-; -;20210217;-...
0
votes
0answers
39 views

How to do sudo grep in a bash script?

I would like to check if the given ip address is already in the config file. But /etc/ can only be accessed by root, and I'm running the a script as a user and not as root. It seems I can't just ...
0
votes
1answer
31 views

Search for specific part of a line

I want to have this script which will store users in the format:<$AccountName> <$DOB> <$Username><$Password> <$Email> on a file called Register.txt. I want to have it ...
0
votes
3answers
37 views

How can I remove characters before and after a text in a chain of characters with Grep, knowing that text is produced through a variable?

I'm using grep 'name=>' log.txt | cut -d\ -f3 I get this kind of result: name=>"Faya-Largeau", name=>"Paris", name=>"Madrid", name is the output of a ...
2
votes
4answers
126 views

Why this word can't be grep?

I have access to busybox only, v 1.27. I'm trying to use a huge TXT file I extracted from a PDF document as a TXT dictionary, to be console friendly. The word I'm trying to get is the very first word ...
0
votes
1answer
20 views

How to zgrep and then gzip multiple files individually?

I have the following code which searches for a term in multiple files (file1.json.gz, file2.json.gz, etc etc) using zgrep, and then using gzip it saves the output into a single file: zgrep -i 'help' /...
1
vote
1answer
65 views

grep -v does not return complement of grep

I want to filter a file for lines starting with a space. I use the following command: grep -v "^ " < input > input_no_starting_space To double check my results, I run the following: ...
1
vote
3answers
52 views

How do I get output using jq in the way it gives me the whole line where a word or string came in

My question is somewhat similar to it but still allow me to elaborate. I have been accessing a weather application called wttr.in from where I can get weather information. This can be easily called by ...
0
votes
2answers
48 views

Grep anything in between two words as long as it's less than specified number of characters?

I'm trying to use something like the pattern "John.*Smith" but instead of matching anything in between John and Smith I'd like to match anything between the words as long as it's of X ...
1
vote
2answers
64 views

regex lookbehind ignore quotes

I have the below string in my file and I want to extract the word after -s, i.e yesterday without quotes : -t -w -g london -s 'yesterday' -e 'yesterday' -f 100000" Required output yesterday ...
3
votes
2answers
154 views

Display grep output with line breaks inside a if statement in a bash script

I want to validate a text file with a script. The file to validate is: FDFHDK JKL 1545665 152 HDKFHDK UHG YRYRUBH DFG 867HDKE WER Valid lines must match the regex '[A-Z]{7}+[[:space:]]+[A-Z]{3}'. If ...
2
votes
3answers
350 views

tar list full filename without directory

I have a tgz file with the following file structure - folder - subdir1 - file1.txt - file2.text - subdir2 - file1.txt When i run tar -tf folder.tgz, it outputs the following:...
0
votes
1answer
28 views

Count the number of times where the next log entry came after one or more minutes than the last one

I have a log file that records the date, time (hours, minutes, seconds, milliseconds), the speed of a vehicle and the free distance between the vehicle and the vehicle in front and back of our vehicle....
-1
votes
3answers
27 views

Store a value from os-release text file after an = sign individually [duplicate]

I want to store the value of os-version from the command cat /etc/os-release. The output of cat /etc/os-release is VERSION="4.4" ID="someId" ID_LIKE="someIdLike" I want ...
0
votes
7answers
223 views

Matching multiple ranges with sed range expressions [closed]

Update: As many commentators have pointed out, my question was ill-formed. Sorry and thank you! I am updating the my question but leaving the old question at the end for reference. Updated question I ...
0
votes
2answers
35 views

grep not working with filename from for loop

learning bash scripting and i'm trying to filter results with a nested grep in a for loop: sample filenames: this-file_AAC.txt this-other_file_AAAC.txt yep-a-file_AAC.nfo oops_another_one....
5
votes
8answers
821 views

How to get names of the files which contain the specified text only

I have a directory named "labels" in which there are text files which contain labels for "cat" or "dog" or both on separate lines. Contents of files in labels directory ...
0
votes
1answer
26 views

Extract Product, number and quantity from a text file

I have improper text file which has product name, website location and quantity. Now I just want to prepare product name, number (extract from URL) and quantity. Input file: rawfile.txt Component ...
2
votes
1answer
48 views

Copy all PDFs within a listing of directories

I am trying to copy all PDFs within a listing of directories to my temp directory. I have this command to get a listing applicable directories: dirname $(grep -r <my search criteria> /c01/app/*...
0
votes
1answer
26 views

Find occurrences in a list of files and count them

I have a large set of thread dumps which are in a directory tree (one folder for each 30 minutes). I'm trying to count how many Threads are in a single file. So far I've come up with: find . -name '...
0
votes
3answers
93 views

Search for pattern and create file with the same name

Here's a simple line of my usage: grep -i '"location_country":"country name"' file.txt >> sample.txt I'm searching a large file with multiple countries and what I would like ...
0
votes
3answers
48 views

Find all lines containing string - summarize and count them

I have a lot of files in several subfolders that include a string type="abc_ - I'm not too sure how many variants of abc_ there is - so I want to know how many occurrences of the unknown type=&...
-1
votes
1answer
39 views

print the lines where two consecutive words never share the same character , uesing grep

i have input like this sie%Qu7s Kuux"oh9 ohc9ahG% hoe8Toh: Eix*ohd1 doh:bo2U Cu0doo|t zo`L9xaW 5ciw3GRd 2sYpKD:T x0OU7Irq #V5ueAF6 7aH;cJOo 1n8(tQwI ivopx2y0 ,69tGqR4 fie5Du[h Phe8aid# Opu&...
0
votes
0answers
43 views

Splitting a file from grep

I have what seems to be a fairly simple problem but I dont know which tool I should use or how. I have a large file, a long list of programs that are archived together. I am looking for lines that ...
-3
votes
4answers
144 views

Print lines where every word of the line with capital letters starts with a different letter

I have this text: FOUR MILLION, EIGHT HUNDRED AND FIFTY-SEVEN THOUSAND, FIVE HUNDRED AND THIRTEEN innovating FORTY-NINE MILLION, ONE HUNDRED AND EIGHTY THOUSAND, TWO HUNDRED AND FORTY-EIGHT championed ...
0
votes
1answer
21 views

When assigning a command output to a variable, the new lines are replaced by white spaces [duplicate]

I have a file and the idea is to grep the content following a pattern ("create mode") and to store this content in a bash variable in order to use it then in a curl statement. I have the ...
0
votes
4answers
78 views

Combine multiple greps with regex

I have this file: 10 replies Big Horse 123sdf562 replies 1354654 Fat Cat 2 replies White Horse Big Cat Little Dog 5 replies 725vgfvjgh123 Black Horse Brown Cow 8798jgjh I want to extract lines that ...
-1
votes
1answer
43 views

Add "+" before every line that gets shown by grep

grep -Fxvf file1.txt file2.txt this shows me The difference between the two Files, which is: Name A Name B Name C but I want that it shows me a "+" before every line. Like this: (I dont ...
-2
votes
1answer
50 views

Does pcregrep (or pcre2grep) have the equivalent of grep's --max-count option?

Take the following file : aaa bbb XXX ccc ddd eee XXX fff ggg I'd like to print, with pcregrep, all lines until the first one containing XXX : aaa bbb XXX Is it possible (with pcregrep or pcre2grep) ...
5
votes
2answers
190 views

what is the use of egrep [[:print:]] command in bash?

I am working on an enhancement of a shell script which reads a file and processes it. Basically the input file contains a header record followed by number of detail records. I want to get only the ...
4
votes
1answer
73 views

grep a range of characters (decimal encoding)

I have a list of accepted characters: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI These characters can be translated in the ASCII decimal range 33-73 The implementation I'd like would ...
1
vote
2answers
79 views

How to find files that only contain alphanumeric characters?

How to find files that only contain alphanumeric characters and [áéíóúñ.,¿?¡!()]? I have some sparse plain text files and I need to separate them from scripts and any other thing, they're just ...
0
votes
2answers
65 views

Using find + grep + awk in combination

I'd need to filter through a list files (output of top command) for some info: Firstly I need to list files with a find Then, I need to grep for lines with a pattern Finally, I need to pickup one ...
0
votes
1answer
43 views

Grep output - expected result?

I have the following grep grep "/abc/[A-Z]" file1.txt | cut -d/ f3 | sort -u The grep worked perfectly returning the results, ALPHA abc BRAVO CHARLIE However, why is the abc in the output ...
3
votes
2answers
540 views

Find returns same path twice, but truncated

I am running this find command: find $HOME * -depth -type d -iname *bowtie* | grep "bowtie*-*1[^2]" My expected out put is: /home/user/Documents/scripts/bowtie1.3.0-linux-x86_64 /home/user/...
-2
votes
1answer
31 views

grep command to grep the gene list in first file present in the gff file

I am using this command to grep the gene list in first file present in the gff file. grep -w -f upregulated_genes_in_BEg GCA_900659725.1_ASM90065972v1_genomic.gff it did not work for me.. please any ...
-1
votes
1answer
45 views

How can I return only part of my grep result?

Currently I have the current command in my script: udevadm info /dev/nvme0n1 | grep P: In order to return the following information : P: /(PCIe address)/nvme0/nvme0n1/ Essentially I dont want the ...
-2
votes
2answers
86 views

grep to extract unique capitalized phrases

The snippet below produces a list of all capitalized words from input text: grep -o '[^ ]*[[:upper:]][^ ]*' book_text.txt > Capitalized_words.txt Now I would like to extract and count the ...

1
2 3 4 5
91