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
28 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
36 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/...
-1
votes
1answer
27 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
4answers
50 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 ...
-2
votes
0answers
30 views

Using Grep in perl script [on hold]

I want to execute the grep command inside my perl script. this is my command : grep -nr "{+" error.txt > error1.txt I want to find this character in file error.txt and want to print the line ...
0
votes
2answers
54 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
40 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
51 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
48 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
45 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
34 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
61 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
68 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
37 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
758 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
62 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
27 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
37 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
41 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
29 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
355 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
37 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
172 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
65 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
52 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/...
1
vote
2answers
42 views

How to grep strings from command output

NAME READY STATUS RESTARTS AGE grepme 1/1 Running 0 20h grepmetoo 1/1 Running 0 19h Result: grepme grepmetoo How to ...
-1
votes
3answers
75 views

How to print first two fields in a file?

I have a file with country names and then the mobile country code prefix for that country like this: United Kingdom +44 ...more fields United States Virgin Islands +1 ...more fields I need to ...
3
votes
3answers
381 views

Grep complete name including dot in the word

In a ksh shell script I am using a grep command to get a specific word as shown below. $ cat file.txt abc xyzdef.123 def.jkl mnopqrst $ grep -o "\wdef\w" file.txt xyzdef def I want output to be ...
-2
votes
3answers
48 views

Perl multiline match for 'something' which starts without '#\s'

UPDATE: The REAL answer to this MULTILINE question was given here by Stephane https://unix.stackexchange.com/a/521560/354415 Alternatively go line by line with perl by Terdon below: https://unix....
0
votes
1answer
43 views

bash script with grep command not [duplicate]

I have this part of shell script : #!/bin/bash shopt -s extglob currentDate=$(date +%F) echo $currentDate command="grep $currentDate" gcs3='s3://gc-reporting-pud-production/splunk_printer_log_files' ...
0
votes
2answers
29 views

For loop to iterate over directory tree extracting results from files of the same name [closed]

I have a series of directories, all with list.txt in the same format, and I wish to put the results into a single file. I am looking to write a script that will iteratively move through each directory ...
1
vote
1answer
94 views

how to grep in the output of ls -a

I'd like to grep the output of ls and pipe it into less so I can scroll through the output. This doesn't work, but ideally, I'd be able to type this: ls -alh | grep "file" | less Any suggestion ...
0
votes
2answers
52 views

Skip lines with matching pattern and delete lines with condition matched

I have file with following format : Q L A D 1 10 2 21 3 22 4 5 5 9 I need to skip lines which starts with 'Q' or 'L' and delete lines where second column has value greater than 10 and save the ...
0
votes
1answer
15 views

Grep matching and looping through directory and store in different output files

I have 3 files as follows: 1.out a b c 2.out g h abcd a h 3.out b c e a I need one line above and one line below in the file where the pattern 'a' matches and stored in the new corresponding ...
0
votes
2answers
103 views

Linux awk grep from file 1 into file 2

I have regex in file 1 .*8912.*.*.*.*81415444.* .*8912.*.*.*.*81415444.* .*8912.*.*.*.*81415444.* .*8912.*.*.*.*81415444.* .*8912.*.*.*.*81415444.* .*8912.*.*.*.*81415444.* .*8912.*.*.*.*81415444.* .*...
1
vote
1answer
50 views

Grep to check filesystem mount and test to check for file path is providing incorrect information

Even though the path exists, this script reports that it does not. What is the flaw in the logic? #!/bin/bash mount="/fileserver" if grep -qs "$mount" /proc/mount && { test -d '/fileserver/...
0
votes
1answer
55 views

Why is my bash shell script changing spaces to linefeeds?

I started out writing a simple bash shell script to find duplicate files within a given directory using SHA1 to detect matches. Everything worked until I encountered file names with spaces. The ...