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
1answer
41 views

bash script - how use a $variable in grep

I am writing a simple bash script where user input the domain name (example.com) and it greps the email address from whois command output. I want only grep the email with the same input domain (xxx@...
-2
votes
1answer
36 views

How to filter by column

Surprisingly hard to find a good example of this one. Say I have this command: ps -aeF the 7th column is the processor # (?). I just want to filter by processses running on the 2nd core. How can I ...
0
votes
2answers
26 views

search multiple files based on file contain string

let say i have one text file contains emails abd3@dom abd2@dom sdklf2@lksd sd@gm i need small bash script for grep , find , to find contain the email in files and and print out the files they match ...
1
vote
1answer
20 views

Show the full path and name of all files that contain keywords in their name

I am new to the Ubuntu system. If I want to display the full path and name of all files that contain keywords in their name. What can I do? I've tried: grep -lR "keyword" . grep "keyword" $HOME ...
3
votes
2answers
187 views

How to subtract number in previous line from current line's using grep?

I use grep to get the output of mysqladmin as sudo mysqladmin ext -i10 | grep 'buffer_pool_pages_flushed' and the output is continuous (every 10 seconds) as | Innodb_buffer_pool_pages_flushed ...
-1
votes
1answer
40 views

I'm looking to pass 1 line of a .txt at a time into a shell script as a grep search argument

basically trying to make a shell script to run a grep on a certain directory for each line of a particular .txt, then output the results to a .txt that is named the same as the argument. for %...
0
votes
2answers
35 views

Bash scripting loop concatenate pipes / redirections based from names variable

I have a command that produces a number of output lines that I later grep searching for. Based on a past answer I know I can use a single long command and do all my filters concurrently: https://...
3
votes
5answers
569 views

How to do the equivalent of a “where” clause with `find` and `grep`

I have a folder tree of text files and I would like to find instances of a substring and the names of the files they came from. If I do something like: find . | xargs cat | grep 'abc' then I would ...
-1
votes
1answer
33 views

What is the difference between grep -r and find here?

I'm trying to recursively grep through files in a directory to find a certain string. The solution of my choice is: $ find . -type f -exec grep "string to find" {} \+ ... while using grep ...
1
vote
1answer
36 views

Collapse grep results into one line while keeping unique values and removing duplicate values?

I'm using zsh but open to a bash solution as well. Suppose I have the following command: ls **/*/assessment(.) | xargs egrep "(^ \[\./.*\]$|^ input = .*$)" Which gives me an output that ...
0
votes
1answer
21 views

How to replace multiple file lines with an edited grep output?

I grep recursively in a directory, now I got an output. Look through the lines, I change lines what I need to change, and remove lines what I don't need to change. like grep.txt ./path/a.c:12345: ...
0
votes
1answer
21 views

egrep regex: having [ and ] or dot in character class does not match

I am trying to match an IPv6 address with square brackets but I am surprisingly stuck... Works: echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \(.+\)\.$' Does NOT match (but I think ...
0
votes
0answers
30 views

Use a regex pattern to search a file and count occurances

I am trying to search the DNS Bind querylog file ( domain requests for DNS) on Linux (raspberry pi) with a pattern to pull out the domains and then tally up the occurances of each domain The ...
0
votes
4answers
42 views

Question about Gnu/Linux command line interface, with grep, ls, and cat

Greetings Stack Exchange, My Goal:Execute ls to search the entire directory structure and grep to search for cats.py. Use cat to read the file cats.py. I know that sounds like Gnu/Linux inception. ...
0
votes
1answer
41 views

Passing Argument to Grep to get specific output

I am a newbie to Unix. Learning on my own.....I am writing a simple shell script to pull the Name of a dealer who was working a shift at the specified time where search takes place from multiple files ...
0
votes
1answer
26 views

Command that only displays ip address and subnet mask using ifconfig

I need help with my Linux laboratories. Does anybody know a combination of command complies with this exercise? Look at the output of /sbin/ifconfig. Write a line that only displays IP address and ...
0
votes
2answers
28 views

Grep F Parameter Not Complete Match

I'm trying to use the -F parameter on a grep to match a PHP variable. When I run: grep -F "$_SESSION['index']" -ri . though it is only matching: ['index'] How can I get it to also match the $...
1
vote
4answers
106 views

Rename file using grep and for

I would like to rename files with following extensions: .txt, .data, .conf to ".xml" hello.txt -> hello.xml To do so, file must also contain the following line: <?xml version="1.0" encoding="UTF-...
0
votes
0answers
25 views

How to search for a specific IPv6 address in a bunch of files?

Let me first state up front my Linux skills are not top tier. With that being said I tried searching for a specific IPv6 address using grep. My attempt looked like this: # grep -o "2607:f388:2:2001::...
-1
votes
0answers
48 views

How to find in a string from 4th letter is numers or not?

for example: I have strings as below string1 :ROSE543 string2 :ROS543 string3 :ROS54SQD string4 :ROSEFLOWER string5 :FLOWERROSE here i have to know the string starts with ROS and from 4th position ...
-1
votes
2answers
55 views

Using find with grep and pass the result to another grep

I'm trying to use find to locate a file and the first grep will look for a pattern in that file. the result will be passed to a second grep like so find /Dime/Lock_Room/ -name CDRV.txt -type f -...
0
votes
1answer
52 views

How to ensure that list order stays the same, when lines are missing?

I run into a problem and can't wrap my head around it. Any help is welcome. Example Correct order, given or in external file: red blue green brown black Input: red blue green black Output: red ...
0
votes
3answers
74 views

one shell command to find every n-gram works in text

I have a text stream or a file that contains words separated by whitespace.  Like: I have a toy. you may not like it. Every whitespace-separated word may be composed by two or more small words, ...
0
votes
1answer
56 views

How would I go about adding new data to a file?

So! I have an nmap scan that saves the output to a file, nmapscan.txt: sudo nmap -sP 192.168.1* > nmapscan.txt I also have a few other commands to clean up and save all desired output to one file,...
0
votes
1answer
20 views

How to tail on demand based on a search and colorized the result

Hi I have a log file that has a lot of information and it is pretty difficult to spot what I am looking for, so I came to this command that show me only what I want to see in the log, it will act as a ...
0
votes
1answer
43 views

How to find files containing string?

I tried: grep "$1-2400000" /media/linux/DATADISK/flashka/ It is running and doing nothing for a long time. Is there another way? It is not necessary to do that with the terminal.
-1
votes
2answers
46 views

how to extract string by Regex with grep?

say I have a SQL.txt select * from table1; select a,b,c from table2 where a=1; How can I filter the table name with the command cat SQL.txt|grep My expected output is: table1 table2 I'm a newbie ...
-1
votes
5answers
94 views

How to filter column in TSV file with bilions rows

I am working with a list with billions rows of data. I have data like this: Like you see, in fourth column (gene column) there exist names of genes but not all rows have a "gene name". I need to get ...
-1
votes
0answers
31 views

how to correlate 3 files and find the best match based on number of hits

I have 3 files containing data like (text.txt) protein1 protein2 In another file protein domain (domainn.txt) pf0001 pf00027 3rd file having domain interaction and their high low value (intrctn....
-1
votes
3answers
41 views

Print out IP address script [closed]

I need to make a script that gets my public IP address from a website and prints it out. #!/bin/bash wget http://www.ipchicken.com/ grep I don't know where to go from here. Please help
0
votes
1answer
39 views

Bash command to count lines with matching substrings in two different positions

I'm trying to get some trivial statistics on some debug output. Each debug line is of the form(class name)(delimiter 1)(object ID)(delimiter 2)(method name)(delimiter 3)(log message) I want to get a ...
1
vote
5answers
41 views

How to extract only the screen resolution information from xrandr output?

xrandr | grep primary return eDP-1-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 193mm I am interested in only the resolution sub-string 1920x1080 from this ...
0
votes
1answer
39 views

How to remove text before delimiter?

I need help on removing text after ); and before | delimiters in all lines of a text file. I.e: SUBSCIBER_MSISDN=6289666195060');BEGIN DBMS_LOCK.SLEEP(5); END-- rKSy| And the result supposed to be ...
0
votes
1answer
20 views

grep lines starting with - or plus from yum command output

I am running a yum query yum group info 'X Window System' where the output is as follows yum group info 'X Window System' Loaded plugins: fastestmirror, langpacks Loading mirror speeds from ...
0
votes
1answer
35 views

How do I extract value of a JSON key using bash shell?

I'm using bash shell. I would like to include something in my shell script that can extract the value of a certain key in a JSON string ... davea$ json='{"id": "abc", "name": "dave"}' I tried "grep"...
1
vote
1answer
40 views

List all mp3 files having over 320 kbps bitrate using bash

I'd like to get a list of all mp3 files with >320 bitrate. I'm not sure, how to apply the regular expression to the output of exiftool -AudioBitrate command. find . -type f -name '*.mp3' -print0 | ...
0
votes
2answers
57 views

lsusb | grep | Awk command is cutting off the first result

I am trying to run a usbreset program against lsusb which has several devices with the same device identifier. I run lsusb to list the devices, and add a | grep [identifer] to only list the devices ...
2
votes
1answer
37 views

Cannot execute commands after logging in to server over SSH when IP is generated by linux command

If I ssh directly ssh user@192.168.13.2, the server behaves as normal and I can execute any number of commands before logging out. The server IP address is very similar to one defined in my network ...
1
vote
2answers
56 views

Create a file with the information about line position of multiple lines

I have a file with the following column: GEOM_190_190 GEOM_190_192 GEOM_190_194 GEOM_190_196 ... Its length is around 3000 lines. I would like to write a script that creates a file with ...
0
votes
0answers
22 views

How to get size of the volume in one line?

I have created kubernetes PVC which is creating volume and mounting into a linux host. I need to fetch the size of the volume. Currently below is the way i am taking volume name and size. To get the ...
0
votes
1answer
27 views

Arch Linux: installing grep from source

I completely removed grep along with my package manager (Pacman) , on accident. Recovering form this issue would be easy but, I can't install grep. I downloaded the tarball and extracted it, but when ...
1
vote
1answer
40 views

Is it possible to write an alias or function in Bash to filter out the errors (stderr)?

I sometimes would do grep -ri foo . but in some node_modules, it could have some links to places that don't exist. So I can do a grep -ri foo . 2>&- or grep -ri foo . 2> /dev/null but ...
0
votes
1answer
34 views

cut -d not working?

I'm trying to extract all the lines from a file that end with /42 and then remove said /42 with the command cut but for some reason its not working. Here is the command grep "42$" questionnaires.txt &...
-2
votes
2answers
52 views

How to replace whole lines with match substrings using 'sed'

I was trying to find a way to know the emails written in source codes. I found a way to get the information I was looking for using grep, but as I'm not really familiar with grep syntax I'm looking at ...
0
votes
3answers
32 views

need to replace a pattern in a file with spaces

I have a file which contains numeric values with hypens / spaces in between; need to replace it with spaces ex: 333-44-5555 / 333 44 5555 grep '[0-9]\{3\}-[0-9]\{2\}-[0-9]\{4\}' grep '[0-9]\{3\} [0-9]...
1
vote
1answer
48 views

Matching two words with constant random characters between them

I am trying to search for a grep command that will allow me to extract two patterns (words) for every line with random sequence in the middle of a specific length (6 in my case): ...
1
vote
0answers
24 views

HTTP logs using tcpflow with grep, redirecting to a file don't work (empty file)

I want to log some specific HTTP requests that have a keyword, that are coming to a specific port. tcpflow works fine, but I can't write filtered results to an output file. I don't understand why ...
6
votes
9answers
434 views

Position, by word count, of all repetitions of a word in a text file

I want to find where a word appears in a text file — as in the number of words into the text that a word occurs — for all instances of that word, but I'm not sure even where to start. I imagine I'll ...
0
votes
2answers
47 views

grep patterns and keep matches on the same line

From the sample input: cat file.txt ID1 sample1 sample2 match1 sample3 ID2 sample4 match2 matchABC I would like to obtain sample output, keeping only the matched words on ...
2
votes
3answers
131 views

how to align hypen

This is my command echo -e "Test sur la vie, l'univers et le reste \n " >test42 |grep '42' questions.txt | nl -w1 -s ' - ' | cut -d "/" -f 1 >> test42 this is the output Test sur la vie,...

1
2 3 4 5
79