Questions tagged [grep]

grep is a command-line tool for searching text patterns in files

0
votes
1answer
19 views

How do I avoid greping matching lines with -

I'm trying to grab only matching lines from a file using grep. The problem is that, when for example I use the following expression: grep -w AFFX-KIT-000088 textfile it will return: AFFX-KIT-000088-...
0
votes
1answer
20 views

Simple Binary Replacement

I tried using bbe as below bbe -e 's/01110011/01111000/' test.txt All I'm trying to accomplish in this example is to read the file as if it's a binary file, and replacing the letter s with x. I'm ...
0
votes
2answers
24 views

Bash - Find ID Pairs on One File Listed in Another File

I have a large file "F1" with listed id-pairs: id1 = digits, id2 = characters id1 id2 id1 id2 ... And I am trying to extract the lines containing the id-pairs from a second file "F2", formatted as ...
1
vote
1answer
26 views

How to grep a data within a square brackets?

I have following type of data in my .log file: Cell[BoxData["0.8693473380926441`"] Cell[BoxData["100.40266203596555`"] Cell[BoxData["23.338724857049048`"] Cell[BoxData["0.25720321805387686`"] Cell[...
0
votes
1answer
28 views

match groups with an inverted match

I need to extract with -o1 a group that is matched in lines that do not contain a string. If I use -v pcregrep does not match any groups - which is reasonable: I'm asking to group-match something in ...
0
votes
1answer
17 views

remove specific sysctl.conf setting

on some of my machines i have this block of setting in sysctl.conf(the numbers are different on each machine) : #Size Of RAM (In GB): 23 kernel.shmmni= 2547 kernel.shmmax= 365482458 kernel....
-1
votes
2answers
46 views

How to replace a matching string if n+2 line does not contain a particular string

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/...
0
votes
0answers
12 views

Retrieve number right after grep command [duplicate]

I have a file with a bunch of text in it. I can grep the file as so cat email1.txt | grep np= which will highlight np= in the file. What I need is to record the value right after the '='. Is there any ...
0
votes
2answers
55 views

How would I implement alternation with regex (Basic Regular Expressions only) in grep?

I am aware that this question does not make much sense, since I could just use Extended Regular Expressions (ERE). But let's say for a minute, that implementing alternation is the only option right ...
0
votes
1answer
40 views

How to grep all unique ip address in /var/log/messages and send them to another log file

I am in the prosses of decommissioning an old Redhat public BIND server and would like to find all unique IP address that are sending DNS request to this Nameserver. So far this is what I have been ...
3
votes
2answers
65 views

Sed to print out the line number

Here is my sample file user@linux:~$ cat file.txt Line 1 Line 2 Line 3 Line 4 Line 5 user@linux:~$ I can print line 2-4 with grep -A2 'e 2' file.txt user@linux:~$ grep -A2 'e 2' file.txt Line 2 ...
0
votes
4answers
43 views

Use grep to search for words beginning with non-word characters

The contents of the file testing.txt are: ls -a cmake --verbose verbose I want to use grep to look through this file and find only the word beginning with "--" i.e. the word "--verbose" However ...
1
vote
1answer
38 views

Grep string which contains square brackets

This is the data 10:43:19.538281|TraceDetail |UPBSStandardGenericBillPaymentComponent.PostBillPaymentTransaction|Total Time 19/06/2019 10:43:19.538281|TraceDetail |...
0
votes
1answer
30 views

grep all strings that start with a certain sub string, and finish with the first quotation mark

I'm new to regex and I'm trying to extract all the unique occurrences of each competition. So it should return FA Cup but only once no matter how many FA Cup games are in the file <Date="2014-02-...
-2
votes
2answers
39 views

Command du -xh / | grep -P “G\t” explained?

Interested in switch -P what does it do? And "G\t" pattern explanation? Please do not explain du -xh or basics of command grep. du -xh / | grep -P "G\t" 5.1G /var/oracle/XE/datafile 5.1G /var/...
-2
votes
1answer
28 views

How to grep for multiple text lines in between unknown and changing html code

Here is my function. ph_relwords () { search="" echo "related words: $@" for term in $@; do search="$search+$term" done wget -q -x "https://www.pornhub.com/video/search?...
1
vote
0answers
20 views

How to grep the first dot [duplicate]

ls -a | grep ^. matches a single character of any value, except end of line. What I want is the hidden file only which is started with . ls -a | grep ^\. matches any one character including . too. ...
0
votes
5answers
112 views

How to replace a matching string if n+2 line contains a particular string

for eg: replace com.icc.id with "abc" if n+2 line (version line contains com.icc.id.version). If it is something else, do not replace. This should be applicable to all pom files present in all sub-...
0
votes
1answer
33 views

How do I find multiple entries in log output?

I currently use grep to find strings in log output. My new task requires that I find multiple entries in individual files. Specifically MAC address entries attached to a switch port. After running an ...
0
votes
2answers
57 views

What does grep -w do?

In here grep is used with the option -w. I did man grep and grep --help to try to find what the aforementioned option does. Neither output says anything about a -w option. What does that option do? ...
1
vote
3answers
30 views

Is there a way to scrape strings in between 2 patterns using sed or grep?

I am trying to extract strings between 2 patter for each line of my log file For example some_string: stuff_i_am_interested_in some_other_string some_string: stuff_i_am_interested_in ...
0
votes
2answers
49 views

bash syntax error: invalid arithmetic operator (error token is “.google.com”) when parsing through array

I have an array of domains that I am attempting to iterate through and check if a string from a file matches any of the domains in the array. However, when the for loop starts, I get an error line ...
3
votes
2answers
56 views

Shell script for files matching a pattern and count occurence per directory

I have the following problem: I want to count migration files per directory. My structure always looks like this: /some/path/app1/migrations/0001_hello_world.py /some/path/app2/migrations/0001_foo....
-1
votes
2answers
50 views

Display contents of the file searched by grep or find command [closed]

I have lots of directories in a certain directory and I am trying to find a specific file present in there. I used grep command recursively and was able to locate the file being present in there, but ...
0
votes
1answer
46 views

Difference between two ways to grep from input file

I have an input file we'll call scan.data. It contains a list of words that I'm going to grep. I've found two different ways of doing this, but I get drastically different results: IFS=$' ' find /...
0
votes
0answers
35 views

Storing a grep outcome into a variable [duplicate]

I've recently begun working with Bash and I was trying to do the following: Format the output of uptime Whenever you input uptime into bash you get something along the lines of: 20:30:54 up 43 min,...
0
votes
0answers
16 views

How do I monitor a Socat mounted COM Port device for a specific Char Delimiter?

I have a code like the following: cat -v -e /dev/tty03 | grep --line-buffered '^F' | while read do echo "Line Found" done How can I setup a timeout for the above While Loop. I want the "while" ...
0
votes
0answers
24 views

run script continuously and check for error

I have written below script and it reads the file and when ever there is any 400* or 500* word it will give me error message, and now I want to add two more functionality to my script. I added the ...
0
votes
3answers
59 views

How to hand over arguments containing “-” in Bash? [duplicate]

I tried to use the grep command to search for a string like -R in a file. But the command thinks, that I am trying to hand over an option like -i for ignore case.
0
votes
2answers
62 views

grep files with pattern A but exclude files with pattern B

I want to grep files which include pattern A (iwant) but I want to exclude files which contain pattern B (idontwant). Example: read -p "...what are you looking for: " iwant read -p "...what should ...
0
votes
4answers
71 views

shell script to monitor current errors in logfile

This script monitors logfile for pattern "ora",pull error details and send email.In this case i want to pull only the last error which come in logfile. I set crontab for every 5 minutes,so grep pull ...
1
vote
0answers
42 views

how to use grep to pull the current errors with specific string in logfile [closed]

i need to write shell script which pulls only current error in logfile with specific string and send email if found. if the logfile has same old error the script should not again send duplicate alerts....
10
votes
11answers
820 views

Grep Match and extract

I have a file which contains lines as proto=tcp/http sent=144 rcvd=52 spkt=3 proto=tcp/https sent=145 rcvd=52 spkt=3 proto=udp/dns sent=144 rcvd=52 spkt=3 I need to extract ...
1
vote
2answers
68 views

Grep Syslog firewall logs

I have a file which contains firewall log like this: Feb 3 0:18:51 17.1.1.1 id=firewall sn=qasasdasd "time=""2018-02-03" 22:47:55 "UTC""" fw=111....
1
vote
2answers
31 views

Bash Grep|awk and print result from different files

I have 2 files which contain IP addresses 1st File: 192.168.1.1:4.4.4.4 192.168.1.2:4.4.2.2 192.168.1.1:8.8.8.8 4.4.8.8:192.168.1.6 192.168.1.4:4.4.8.8 2nd file: 4.4.2.2 4.4.8.8 Now I want a ...
0
votes
1answer
35 views

Find file name in content of other file [closed]

There are many text file in folder. I want to know which file's contain that mention to other file name in folder example: Is name of file1 has mention in other file in folder1? folder1 ├── folder1....
1
vote
1answer
38 views

How to grep characters with their unicode value?

I have the Unicode character ᚠ, represented by its Unicode code point 16A0, in a text file (the text file is encoded(?) as utf-8). When I do grep '\u16A0' test.txt I get no result. How do I grep ...
2
votes
1answer
57 views

Is it possible to egrep these symmetrical expressions over {0,1}

The goal is to use solely egrep to match expressions where n occurrences of 0 are followed by exactly n occurrences of 1 and where no 0 follows a 1. e.g. 01 000111 000000111111 but not: 001 011 ...
1
vote
2answers
42 views

regex for a timestamp HH:MM:SS?

In a file named result, containing this: <span class=timestamp><b>15:31:00</b></span> How to grep for the timestamp? Here are some tries and their output: > grep "[0..9]*...
2
votes
2answers
35 views

Regex to check arguments of command

I want to use grep to check if a command called cmd that was ran, contains the word name as an argument. (I know about about !* in Bash, I don't want to use it). Let's say I have the command in a ...
0
votes
2answers
30 views

Using grep and logical operators for pattern matching within shell script

Im trying to develop a script that finds a specific pattern in the output of the dig command running against a list of domains. To do this I'm using grep but having difficulty implementing this using ...
0
votes
1answer
61 views

If/else within a grep statement

I am trying to find all instances of "type":"FollowEvent", and then within those instances, if the string "actor": is not followed by {, then capture the string enclosed in " that comes immediately ...
0
votes
0answers
33 views

PID and process counts do not match from ps with grep output

Using: Red Hat Enterprise Linux Server release 6.10 (Santiago) Scenario: I am trying to automate a process that will capture running processes and put the PIDs and processes into their own arrays, ...
2
votes
5answers
359 views

Using grep to filter

Suppose I have a file.txt with the following lines : hello myname1 is yellow.pcapng red festive myname33 is hddd.pcapng dfdf crude myname44 is hello.pcapng Now my goal is to filter to the lines so ...
0
votes
2answers
37 views

grep freezes up

I'm having trouble using grep, I have ubuntu 18.04 installed on Win 10. It freezes up for the simplest of commands, I can cancel it and it makes a new file if I want to, but it doesn't write anything ...
0
votes
2answers
38 views

How can pass the stdout to the last comand?

I am trying a search with locate only in the current directory, for do this I am using the following approach: locate file | pwd | xargs grep the problem is that the locate results are lost into a ...
4
votes
3answers
181 views

grep exact match two parts of a string

How do I use grep command to get part of string as below? String: orange:"orange", red:"apple", purple:"grape", yellow:"banana", green:"watermelon" red:"strawberries", yellow:"lemon" What I want: ...
1
vote
2answers
70 views

selective deletion of lines between two patterns

I have a file which contains following content, Hello world Unix!! Its bright world Current time is HH:mm:ss Next action plan is item #3 End of task. Thank you. Hello world Linux!! All actions ...
0
votes
2answers
53 views

grep selectively

I have a file of 1000+ designators that from bash I use for desig in $(desfile) do grep $desig in listfile done listfile can every 1 million + lines, so speed is important The problem is for ...
0
votes
0answers
27 views

Grep each line from list [duplicate]

So I have a big list of strings, which I wish to use in a grep command. Doing each individually would be very very time consuming, how could I grep each line from a list systematically/...