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
6
votes
1answer
342 views

Select lines based on length

I would like to use grep or another suitable tool to look for (and print) lines not based on some pattern, but on the length. Assume I have a file that contains two lines, where Line 1: length = 300 ...
0
votes
1answer
32 views

Print Multiple Substrings Including an IP Address

Good day! I have a giant input file that displays a lot of garbage and I would like to export multiple substrings. The problem is that sometimes additional information is injected into the file making ...
10
votes
4answers
803 views

Removing files based on MIME types in linux

I'm quite a beginner to Linux and I'm having trouble removing files based on the mime type. Currently, I have a set of files on my Linux machine, and below are the types for a small subset. 0FiTahKc: ...
-1
votes
3answers
65 views

Extract two columns from file using and sort 2nd column

Have a file with the following format... ATOM 126 CD GLN A 449 -2.853 11.592 119.709 1.00 17.95 C ATOM 127 OE1 GLN A 449 -4.056 11.297 119.695 1.00 20.83 O ...
-1
votes
4answers
61 views

Compare two files and generate another on matching condition

I have two files, a.txt and b.txt, where a.txt contains lines starting with "zn", e.g., zn12c5b or  zn4i8l, while b.txt contains lines ending with a pattern "/number", e.g., t17v11/...
0
votes
3answers
350 views

How to limit grep to scan only the first 10 lines?

I got a command foo that output a list of files separated by \n line. I am using the below command to filter the results by regex content of the files. foo | xargs grep -l regex The problem is that ...
7
votes
2answers
250 views

Grep inside /sys file returns nothing

I want to search for a string inside the /sys/class/tty/* directories. So I tried with: # grep -rn path -e pattern but it returns nothing. Example: # cat /sys/class/tty/ttySTM0/iomem_base 0x40010000 ...
1
vote
1answer
75 views

How to extract domains related to “Client Hello” in a pcap file

I have a tcpdump (pcap) capture file and want to extract all domains. I do it with the following command: strings capture_file | grep -oiE '([a-zA-Z0-9][a-zA-Z0-9-]{1,61}\.){1,}(\.?[a-zA-Z]{2,}){1,}' |...
4
votes
3answers
484 views

help to grep/print value of a key in json that is stored in a variable?

I have a variable with nested json, a={"version":"3.0","user":"unknown_unknown","dateGenerated":"2020-07-08T11:53:23Z","status":&...
0
votes
3answers
78 views

Read a word in XML between elements using sed command

I want to read a word between two xml elements using sed command. For e.g. in below xml, I want to read the number 1234567. <ns1:account> <ns2:name>Corporation</ns2:name> &...
0
votes
3answers
68 views

What's the best way to grep in more files for a line that starts with a sign

I organize all my text notes in AsciiDoc files. AsciiDoc is a file format similar to Markdown but instead of # I use = to denote a first level-heading, like so: first-file.adoc = How To Install MySQL ...
1
vote
1answer
38 views

Update data using search & replaces

get_data.txt ald900 NON-Prod GOOG037-A US ald9024 NON-Prod GOOG037-A SRI-LANKA ald978 NON-Prod GOOG037-A JAPAN I have two given data. I need to search in get_data.txt ...
2
votes
1answer
105 views

How do I grep output from git?

I'm trying to extract the name of the folder created by git. The output says: ... Cloning into 'repository-name'... ... I want to pipe this output into grep to extract the one line that says Cloning ...
0
votes
6answers
108 views

Split each line by a delim read from another file and store all split word compounds in the result file

I want to split each line from file names by each and every delimiter from file delim and store the unique word compounds into result file compounds. Lines from names that were not split should be ...
5
votes
6answers
2k views

Grep all lines with exactly one instance of a specific character

I want to grep all lines with only one "#" in a line. Example: xxx#aaa#iiiii xxxxxxxxx#aaa #xxx#bbb#111#yy xxxxxxxxxxxxxxxx# xxx#x #x#v#e# Should give this output xxxxxxxxx#aaa ...
2
votes
4answers
138 views

How to speed up grep on large history?

I have an unlimited .zsh_history which is currently at 10k lines. I often want to see all commands from history that have a certain string, for example curl. If I do history | grep curl it takes a ...
1
vote
3answers
540 views

Grep lines that match pattern twice

Usually grep outputs any lines that match a pattern. I want to be able to find lines that match the pattern multiple times. For example, if my search pattern was "foo", then: foo bar #...
0
votes
1answer
133 views

How can I remove source code based file types in linux?

I have a list of raw files that were scraped and it consists of both text and source codes. Below is the filetypes listed and I wanted to remove all files which are of type C Source, python script, ...
0
votes
2answers
64 views

How can I select a record line from a file using SED

Apologies... Code that I shared earlier is incorrect, revising... Revised Question: First of all, I would like to apologize for the rush, I am new in QSHELL and just started learning.. But I badly ...
-1
votes
1answer
30 views

find line with repetitive pattern

I have a log file like this 123.123.123.123 (456.456.456.456) abc def ..... 123.123.123.123 (123.123.123.123) abc def ..... 123.123.123.123 (456.456.456.456) abc def ..... 455.455.455.455 (456.456.456....
0
votes
1answer
28 views

Sorting file based on “file” output into folders

I am having millions of files without extension and I want to sort them into various folders. I am able to identify the files by "file" but then I end with lot of different types which I can ...
2
votes
0answers
48 views

Make grep exclude a specific directory [duplicate]

The context Consider the following directory $ tree -a $(pwd) | sed "s,$HOME,~,g" ~/mytest ├── 1 │   ├── 1.txt │   └── 2 │   └── 1_2.txt └── 2 └── 2.txt 3 directories, 3 files and ...
2
votes
0answers
91 views

grep returns lines with no matching text and does not provide line number with -n flag

I have a large csv file with over 1 million rows. I am getting some strange hexadecimal looking output in some rows that don't match the rest of the data. I wanted to use grep to quickly find the ...
0
votes
2answers
45 views

finding multiple strings in a line

I'm brand new to Unix and am using CygWIN64 simulator. I have a huge number of text files (tens of thousands) that I need to search for specific strings. I have had success teaching myself to search ...
0
votes
5answers
89 views

How to parse a line which has a number after a certain string greater than a threshold?

I have a file (list_20.txt) that looks like this: [{"d_prime":"0.475425","variation1":"rs909776","r2":"0.057940","variation2":&...
1
vote
2answers
98 views

How to grep the string right after given string

I have a log file myfile.log which is having below content Thu Jun 04 09:02:05 2020 Closing scheduler window Closing Resource Manager plan via scheduler window Clearing Resource Manager plan at ...
-1
votes
1answer
88 views

Grepping Linux logs on the basis of source IP and user name

I have a server logs which contains data like sourceip="1.1.1.1" and username="aaaa". Need a command to grep the entire log file and Search for multiple logins from same IP address ...
1
vote
1answer
29 views

grep does not colorize properly

I am trying to pipe a output from command to grep. $ strace a.out | grep --color=always "mmap" but it only outputs non-colorized output of strace: ... mmap(NULL, 503808, PROT_READ|...
1
vote
3answers
213 views

Grep string inside double quotes & single quotes

I want to find the string inside double quotes or single quotes in a text file(the text file is multiline), for example: I have a test "foo bar1" test2 "foo\"bar2", "...
0
votes
0answers
112 views

zgrep large number of files with regex pattern

I am attempting to search a large number of .gz compressed files in a single directory using zgrep. The files in this directory represent the logs for a service I am working on. In these files I am ...
0
votes
1answer
44 views

How to grep only json files(exclude.json.gz)?

I tried this grep -r --include=\*.json 'ticr_calculated_3' ./ Got nothing,although I have files tick_calculated_3_2020-05-27T11-52-59.json tick_calculated_3_2020-05-27T11-55-08.json ...
0
votes
2answers
49 views

grep between 2 files and perserved empty line of file 1

I have a problem with a grep. I have a file called Uniprot_interactors.txt containing a list of codes (ex. GRT986E) and sometimes between objects there are one or more empty lines. In some other cases ...
1
vote
2answers
60 views

Is it possible to use grep or awk to report duplicate output lines corresponding to repeating entries in an index file?

I can't seem to get either grep or awk to do a relatively simple index pull of a list. I suspect it's because of adjacent duplicates in the index file, something I wouldn't have thought would cause an ...
2
votes
2answers
103 views

How to extract lines from a textfile that contains string from a list in another file in order of search list?

File 1: sourcefile.txt Hello, It's the beginning of the sentence. it is the beginpoint of my career. The end is always far. We can start our beginpoint anytime we want. The time we utilise to make ...
0
votes
3answers
1k views

How to get group results using grep?

How would I get this output: Found value: This order was placed for QT3000! OK? or Found value: This order was placed for QT300 or Found value: 0 using line.txt and pattern.txt as below: [nsaunders@...
1
vote
1answer
49 views

grep -no is not functioning properly

Typically when using grep -no every single match has a line number. For example when typing grep -no "[A|a]" chr22.fa I expect: $ grep -v ">" chr22.fa | grep -o -n "[A|a]&...
0
votes
0answers
41 views

Using awk and local variable for filtering [duplicate]

I have a command: $var=test_file_20200612000000 aws s3 ls [s3 bucket name] --profile [profile name] | grep "test" | awk '$4 > $var' This is looking at files on an s3 bucket and ...
0
votes
1answer
37 views

grep not saving all lines

Hi someone from the community write this code. The problem is that when I am trying the save the output from grep in my Positivos.txt file it only saves the last day and not all the loop. I try using ...
0
votes
1answer
355 views

Filter files on a s3 bucket based on the file name

I have an s3 bucket which has files named as such: example_test_20200612010000 example_test_20200612020000 example_test_20200612020000 example_control_20200612010000 example_control_20200612020000 ...
1
vote
2answers
48 views

How to get a certain line from multiple files in linux?

I want to get a line where the first column has a certain string from 5000 files. File 1 agd fkg fls ofk ggs kkg ikg gkl bsg ksf olg lzj many more lines,,, kgf kkg ikg lgk File 2 gik zlg olg pzk ...
1
vote
2answers
24 views

Searching a file for a string in an array

I am trying to check if items in an array options are in a file $file using the following simplified code: options=( A B C ) for i in "${options[@]}"; do if grep -F $file &...
-2
votes
4answers
58 views

How do I count all letters in a column, alphabetically

How can I count all letters in a column from "a" to "z" in a .tsv file with an output telling me how often each letter appears? For example lets say this is a column abc abd aabf ...
1
vote
1answer
40 views

Unix take all data from a column that contains a letter

I want to take all the data that contains an "M" in the 3rd column and place them into a file. I attempted the following code(s) but when I try to execute the new folder nothing shows up its blank. ...
0
votes
1answer
221 views

Grep a key value pair in JSON as CLI

I have a big Datalog with JSON. One JSON element looks like this: { "context": { "callback": { "Data": { "LastSessionTime": "2020-06-07T09:16:19Z", "TrackingEnabled": "1", ...
1
vote
2answers
45 views

Grabbing chunks of log files that have multiple matching criteria, but the matching criteria is not on the same line

code: grep -rI --exclude=*_*.log -B20 -A1 "Status: Error" > /var/log/alertError.log Input log example: [06/07/20 20:38:53.911]:loopback ST: token-src-name() [06/07/20 20:38:...
0
votes
2answers
170 views

find + grep to Search for Files Containing Multiple Strings [duplicate]

I have the following being sent to my command line: find /base/dir1 /base/dir2 -type f -exec /x/y/z/grep -e lolol -e wow {} + This returns each file containing one or both of the supplied strings (...
1
vote
3answers
366 views

Grep Lines from File with spaces

I have File which contains Records qwe.google.com IN A 1.1.1.1 qwe.google.com IN {uneven-space} A{space}1.1.1.1 qwe.google.com IN CNAME asd.google.com I need to grep all the lines which ...
-4
votes
1answer
222 views

RegEx to Match *ONLY* IPv6 Global Unicast Addresses (GUA) from logs

There's next to no tools for IPv6 security, so want to roll my own solution which I will later opensource. SO: I need a RegEx to sift through logs for remote IPv6 connections to analyze and process ...
-2
votes
2answers
29 views

How to extract from a file lines that don't have any of 4 strings?

I have a file like this: #CHROM POS ID REF ALT A1 A1_FREQ FIRTH? TEST OBS_CT BETA SE Z_OR_F_STAT P ERRCODE 1 740284 rs61770167 C T T 0.0031746 N ADD 21420 NA NA NA NA ...
5
votes
4answers
908 views

How do you search and print multiple matches per line with grep -o?

I have a mkdocs instance and am writing a script to print internal links in a page. I cannot get grep to print only the matches if there are multiple per line. This is what I currently have: $ grep -...

1
3 4
5
6 7
85