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
-2
votes
3answers
73 views

grep lines having “CC” but not more C [closed]

For example, I have the lines: CCP2007 CCCP CCCCPPPPCCC CCCCCPPPPPCCCCC I want to show the first one, the CCP2007, because there are only two letters C in the row. What's the command for it?
0
votes
2answers
72 views

grep in limiting

I have a YAML file: - name: scheduler-configuration - name: scheduler I'm grepping some thing like grep "scheduler" file.txt The output it is showing both lines, but I want only single ...
3
votes
4answers
115 views

Using grep to get the count of files where keyword exist [closed]

I am trying to get the count of files which has matching keywords in directory. Code I used is: grep -r -i --include=*.sas 'keyword' - This gives the total count of keyword. grep -l "keyword"...
0
votes
2answers
36 views

grep multiple words that have space

I have logs file that contain date and username something like below Nov 05 14:36:03.752146 server.com [2020-11-05T14:36:03.752Z] [C 7f7e597fa700] R=6ssssdsdsd 91,CN= user1 drop: UP 10.11.100.100 TO ...
0
votes
1answer
42 views

Extract numerical values from a particular <div> block in a webpage

Objective: extract numerical values from a series of span blocks embedded in a certain div block on a remote server using curl I need to extract some numbers from a status page and have identified the ...
-1
votes
2answers
54 views

I wan to remove special characters and put same number of space between

I have a text file of some special characters: L$+M)jX];&?+jip=ZjJ#}^yV5;fBQ=$L+tG=#x4kDh('t%BWBG/P|U9M`,pcII*6G<r I wanted to remove some of the characters with a similar amount of space ...
1
vote
1answer
36 views

How can I keep the color output of git status when piping it through grep?

I'm trying to compress the output of git status a bit, for a "system status" script that runs whenever I log in to an ssh session. I'm hoping it'll nag at me and encourage me to commit more ...
0
votes
1answer
27 views

Grep: Combining -o and -v flags does not work

I want to combine the -o and -v flag of grep. But i do not get any output. I have the file: foo bar foobar I call: grep -vo foo ./file What i expect: bar bar or bar bar But i get no output. From ...
0
votes
4answers
65 views

Extract the first percentage from a string

I have a string: Identities = 99/100 (99%) total 0/0 (0%) How do I extract just the 99% (number within first parenthesis) but not the 0?
0
votes
1answer
60 views

How to locate a file created through the eXist-db database tool eXide?

I'm trying to find a specific file: note.xml which eXide would seem to have saved. Where is it? I've tried: sudo find / -iname \*.xml | grep note and a few varieties. Perhaps it's not "saved&...
0
votes
1answer
35 views

How to use tree with grep and find to locate files by name?

How can I use tree and either grep or find in conjunction to find, for example, csv files using ".csv" as a file extension: ├── ./Videos ├── ./vscode │   ├── ./vscode/foo.csv │   ├── ./...
0
votes
1answer
28 views

Conditional echo based on results of grep

I have the following command that will output how many connections I have on a given port: while true do echo -n "number of connections: " netstat -an | grep ESTABLISHED | grep -w &...
4
votes
4answers
357 views

How to Compare two files and then append line that is not a partial match?

I am trying to compare two files (Extensions.txt and Temp.txt). If there is a line that does not partially match from Extensions.txt in Temp.txt I would like to append the missing line to Temp.txt. ...
0
votes
3answers
96 views

Delete lines which match with words in a file

I have a file with different words which correspond with my patterns WORDS.TXT 842 897 907 967 995 1065 1095 And other file containing the lines that I want to remove when match with the word.txt 816....
2
votes
2answers
45 views

How to validate a line if followed by a specifc line?

On some our Linux servers we have the following files: /etc/ambari-agent/conf/ambari-agent.ini The files include the following example of lines: ; memory_threshold_soft_mb=400 ; ...
0
votes
2answers
38 views

How to search for a line before a pattern using sed or grep

I have a log file ouput.log and the contents on the log file is as below. The log file comprises of multiple .sql files output in a sequential manner. The log file will have which SQL file is being ...
-1
votes
2answers
58 views

How to match line in fstab file

we have the following line in /etc/fstab file /dev/mapper/vg_D /data/container xfs defaults 0 0 but when we try to match the line as LINE=/data/container grep -qxF "$LINE" /etc/...
-1
votes
1answer
42 views

How to extract mutliple text lines within xml file by using grep and/or sed

I am trying to extract some lines within a <w:t> tag in front and </w:t> tag at the end of the text I want, but im only getting the text within last tags and not the others. How can i do ...
0
votes
1answer
26 views

Cutting date from a file

Right now, I have a cron job that looks like this: */15 * * * * cp /home/server/server_log.txt /var/www/html/logs/`date "+\%d-\%b.txt"` >/dev/null 2>&1 It works perfectly. However,...
0
votes
1answer
24 views

Print text that appears after a substring match using awk in Perl

I have a multiple strings, as shown below, in a file MyFile- 1234|5|678|ABC|d|e| MyString - values: foo 1, bar 10%, baz 2/2, qux quux 10 sec, quuz 10km How to print the substrings 1234 10 sec based on ...
2
votes
0answers
67 views

bash + how to avoiding duplicate entries in authorized_keys (ssh) in bash

Popular methods of adding an ssh public key to a remote host’s authorized_keys file include using the ssh-copy-id command, and using bash operators such as >> to append to the file. An issue ...
-2
votes
1answer
37 views

Search file and grep numeric range [closed]

I have a file which contains a column called salary. This column has various salaries. Using grep I want to get all values between 10000 and 15000. How can I do this?
-3
votes
1answer
47 views

Basic command problems

I tried to figure out what is the difference those commands (for a school project), but for me its chrashed or running for more than 10min~ So, the sample: sudo find / -type f -exec file ’{}’ ; | ...
0
votes
1answer
33 views

grep + when need to add backslash before dot character

Under the folder - /var/my_private_pkgs We transferred packages that are split from ISO rhel 8.0 rhel8.0aa rhel8.0ab rhel8.0ac . . We are doing the following in order to verify the ...
1
vote
2answers
49 views

Find word or a set of words in a set of pdf files

Suppose I have a directory Note_De_cours containing 8 other directories, i.e. Semaine_1 Semaine_3 Semaine_5 Semaine_7 Semaine_2 Semaine_4 Semaine_6 Semaine_8 Each of those directories contains ...
4
votes
2answers
587 views

Why is egrep ignoring the negative whitespace?

Why doesn't grep -E work as I expect for negative whitespace? i.e. [^\s]+ I wrote a regex to parse my .ssh/config grep -Ei '^host\s+[^*\s]+\s*$' ~/.ssh/config # cat ~/.ssh/config Host opengrok-01-...
2
votes
3answers
368 views

grep - print the file name for the file grep currently is searching in

I don't have a problem with getting the name of the file where grep finds a match, however, something in the file hierarchy I am searching through takes forever (hours) to search (it is 1,4 GB data in ...
0
votes
2answers
78 views

Searching for text patterns in a log file

I have a large log file where all the lines contained are of similar format. They can vary a bit, but the format until the first ] bracket is always exactly the same. 31.7.112.60 - - [26/Jan/2019:19:...
0
votes
1answer
63 views

How to store number of unique IP addresses in log file by date?

New to this community. I doing this in bash script. My question pretty much summarizes what I am looking for. I have a log file that has a bunch of IP addresses amongst other data. I want to count the ...
0
votes
1answer
63 views

“grep” usage on Solaris

I did a R package with a function that runs the "grep" system command. This package has been published on CRAN, and the tests on the Solaris platform return an error. This is likely due to a ...
3
votes
4answers
363 views

Replacing regex matches in one file with lines from another file [duplicate]

I'm trying to replace lines that match the regex => '.*', in one file with lines from another file. Two example files. File 1: 'text_clear' => 'Clear', 'text_search' => 'Search', '...
0
votes
1answer
66 views

How to pgrep to find a bash script on macOS (or how to programatically kill a script running in the background)?

I'm trying to programatically kill a bash script running as a background process (on macOS). The way I've settled on for now is to pgrep the name of the script and then pass the PID value to a kill ...
1
vote
1answer
34 views

Match contents of first file with second to generate third file

Sample data of my first file first.txt is below: 10.0.0.1,Web Server,comments1,jboss is older version,myappcode1 10.0.0.3,Web Server,comments4,httpd is latest version,myappcode15 10.0.0.7,Web Server,...
4
votes
4answers
237 views

Grep the data only (-o) and the first column

Sample data wolf@linux:~$ cat data.csv A,4.4.4.4,4.4.4.5,4.4.4.6,3.3.3.3,3.3.3.4 B,1.1.1.1,1.1.1.1,1.1.1.2,1.1.1.3,3.3.3.3 C,1.1.1.1,1.1.1.1,1.1.1.1,1.1.1.1,1.1.1.1 D,2.2.2.1,2.2.2.1,2.2.2.2,2.2.2.3,...
0
votes
0answers
46 views

How to kill the tail -f process after finding the special string? [duplicate]

How can I kill the tail process after having found special command tail -f filename | grep -m1 " special string" | tee txtfile After founding the "special string" the tail ...
0
votes
2answers
73 views

Shell script to tail a log file and output it to another file till specific string is found?

I have to write the output of a log file using tail to another file till it finds the string . Log file contains- I am Rahul. I have 5 oranges. The end. Something something. Till " the ...
0
votes
2answers
83 views

Grep regex to extract only the subdomains

I have this list in a file on my Linux machine: sub1.site.com sub2.site.com.edgekey.net subs.site.com.trafficmanager.com sub3.site.com I want to select the following from that list: sub.site.com And ...
-1
votes
1answer
51 views

How to search for lines that fulfill more than one criterion in Unix?

I want to find the number of the lines that have both words/patterns "gene" and "+" in them. Is this possible to do this with grep?
0
votes
1answer
59 views

Discriminating between log entries' timestamps from bash script

My Bash script executes as a cron job. It seeks a string within a log file and is supposed to forward the corresponding log entry by mail if found. My script works but floods me with already reported ...
0
votes
4answers
88 views

awk match string and sum column values

I'm trying to match the word United States from a folder containing 5 csv files, However, the command I'm using checks for single occurrence in the line. I also want to sum other two columns based on ...
1
vote
1answer
72 views

How to make grep to blink the matched pattern?

What color-schemas should I set to grep's GREP_COLORS ENV-Variable to enable the blinking mode on matched pattern?
1
vote
5answers
377 views

Strip first part of each line to colon [duplicate]

So I have a textfile of which I want to remove everything to the first colon (including the colon). So for example if this is the input 0000007ba9ec6950086ce79a8f3a389db4235830:9515rfsvk ...
3
votes
4answers
481 views

grep up to 3 spaces with \s

According to the following tutorials https://linuxize.com/post/regular-expressions-in-grep/ \s Match a space. and https://www.guru99.com/linux-regular-expressions.html Some interval regular ...
2
votes
1answer
24 views

Grep between 1st occurence to 1st other occurence

It's my first question here ! I've tried many grep, still not found what I wanted ... So, here we are. I have many many files on my Ubuntu machine that contain things like this : {"group":{&...
0
votes
1answer
32 views

loop using grep and adding to file

I am trying to loop a netstat and grep the results by some values, and then if they match- add them to a file, but it doesnt do a grep, but just adds the whole file: #!/bin/bash while true do sudo ...
-1
votes
1answer
51 views

grep and re-direct to csv

This is the campaign log that I am parsing. Based on call-id I do grep. Orginal Progress-log as follows: FilePlayer::run:: Finished audio file is /voip/VoiceCampaigSetup/wildfly-10.1.0.Final/...
0
votes
2answers
77 views

grep from file that contains multiple columns

I have a file called someNumbers.txt with numbers separated by tabs, like: 1 1 2 1 5 1 7 1 10 1 I would like to search the numbers in the first column of someNumbers.txt in the first column ...
0
votes
2answers
42 views

regex fails when trying to match whole word

Here is my test file test.txt hello user1 ALL=(ALL) NOPASSWD: /usr/bin/* /app/tomcat/tomcat*/webapps/*, /usr/bin/rm -rf /app/tomcat/tomcat*/webapps/*,/bin/rm -rf /app/tomcat/tomcat*/webapps/**.sh , /...
1
vote
1answer
48 views

Exclude a list of filenames while removing files

I want to remove all the files under directory assets/img/fly that are not needed in _posts/2020-10-05-most-beautiful-story-i-ve-ever-heard.markdown. These are the files to be excluded: ± |master → ...
0
votes
1answer
74 views

How to get just the first match from grep?

I am writing a script, and I am using this as a variable. RESULT1=`ps -ef | grep -w "PHANTOM PHA-WRM-EXPIRE"`. What happens is that ps is listing two PIDs. [xhobando@noitu TNOITU]$ ps -ef | ...

1
2
3 4 5
85