Questions tagged [grep]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
24 views

Append to crontab only if entry does not exist

I am looking for a programmatic way to append to crontab only if the entry does not exist. Also, the exit code must be 0 for both cases where the entry does not exist, or the entry exists. I tried: (...
0
votes
1answer
24 views

netstat how to exclude localhost from the result when using grep

When I run this command in my terminal: netstat -an | egrep ":80|:443" | sort I got this following output: tcp 0 0 172.104.10.125:48310 172.104.10.125:8081 TIME_WAIT tcp ...
0
votes
0answers
17 views

Reverse grep with whitelist

I would like to parse the output of a command with a whitelist that, in case even one symbol is found in a line that is not in the white list it should be assigned to the variable, something like this:...
0
votes
1answer
27 views

How to grep lines only with matched words in Linux [closed]

I have a little question. I have a list of processes. After this command ps aux | grep postgres I see postgres 1178 0.0 0.2 320064 27060 ? S Apr12 0:05 /usr/lib/postgresql/10/bin/...
0
votes
2answers
34 views

How to remove old kernel on Ubuntu operating system

I am wondering how can I do remove old kernel from Ubuntu operating system. Please refer image screenshot taken. Please advice. Many thanks. list of linux kernel
1
vote
1answer
26 views

How to quickly check if specific keywords exist in a lot of log files in shell?

I have run a program that writes a lot of log files in a lot of directories. For example, there are hundreds directories, and every one includes thousands of log files. I need to find out the files ...
0
votes
1answer
48 views

check ip is present and update iptables openvpn

I want to check that the ip is present within the ccd folder and push the ip route to the FORWARDING chain in the iptables. Im new to bash scripting and need a little help finishing this script. ...
0
votes
2answers
40 views

Extract string from column with grep

I have a column based .txt file and I want to grep output the Common Name, having a little trouble. V 300223164711Z 01 unknown /C=UK/O=LMG/OU=server/CN=server/name=server/emailAddress=...
0
votes
1answer
38 views

Script to grep large file [closed]

I have a file that has about 63000 row I need to grep though [root@server]# cat missinglinks.txt 69870 1.pdf.Published 125098 2.png.Published 125022 3.pdf.Published 69867 4.png.Published I have a ...
0
votes
1answer
27 views

How to print only Users list and Access level from /etc/sudoers?

We have multiple servers and i would like to print users list and access level using bash. I tried below command but could not get exact result what i wanted to: awk '/Allow root/{p=5} p > 0 {...
0
votes
2answers
46 views

How to filler out iptable result base on certain fields and view it with tail command?

I have this log : Jan 26 01:05:47 server54 kernel: [41s58.6w4335] INPUT:DROP: IN=eth4 OUT= MAC=d3:ss:43:23:23:43 SRC=1.1.1.1 DST=127.0.0.0 LEN=40 TOS=0x00 PREC=0x00 TTL=254 ID=65259 PROTO=TCP SPT=...
0
votes
0answers
37 views

View 503 errors in real time?

I know I can use tail -f /access.log to view my log file in real time. Can I use tail or grep or some sort of combinations to only view 503 errors in real time within that log file?
0
votes
0answers
28 views

Creating a script for Kickstarting servers; issue with created softraid 1 server based on CentOS 7

First off; I am sorry if my title is incorrect, but I didn't want to "clutter" it too much. I am creating a bash script which is used to install various servers based on CentOS 6 and CentOS 7 with ...
0
votes
1answer
250 views

From a string, formatted as a table with spaces, how to grep all values that are equal for all columns?

The question comes from the issue: https://github.com/kubernetes/kubectl/issues/717 Kubectl returns information in a table like this: $ kubectl get replicasets -n kube-system NAMESPACE NAME ...
0
votes
1answer
30 views

Filter ss process output without using grep

ss -p can give the process name, process id (PID) and the file descriptor associated with the connection. Example: ss -tuanp [...] tcp ESTAB 0 0 x.x.x.x:59594 x.x.x.x:993 users:(("...
0
votes
1answer
203 views

Not logic in docker filter

I have a named container that may or may not be up and if it is up I want to be able to kill all the containers but that one by name. Basically what I want is: docker kill $(docker ps -aq --filter="...
0
votes
2answers
121 views

Parse Date from Text String in a 3 column format

I am given an array of lines from a text file. They look similar to this, and will always be structured like this: Full Tue Aug 27 10:59:43 2019 1 ...
1
vote
0answers
36 views

Why is sudo password entering lost

When I use sudo command and pipe it to another command, e.g. sudo dnf search foo | grep bar there is a prompt requiring to enter the password. Following this answer, sudo directly accesses the ...
0
votes
1answer
100 views

grep for an array entry in a file

so I have a file step1 containing data like field [T]:0.000 heatstart [s]: 1.50E+1 a[a],b[b],[c[c],d 1.02E-1,2.31E-1,... 1.50E+1,4.26E-1,... ... and a file called var4 containing only the entry 1....
0
votes
1answer
43 views

How to create an alias that uses a value and grep on a remote server?

I need help, I can't create an alias with a variable to grep a file on a remote server. I have tried: alias searchword="ssh -t user@server "grep -i \"$1\" /root/file.txt\"" alias search="ssh -t ...
0
votes
2answers
147 views

grep exclude multiline pattern

Searching for multiline patterns in files with grep is trivial. Inverting that pattern not so much. Background: I want to create clean variable files without passwords so I can commit them into a ...
0
votes
1answer
188 views

How do I grep last match in a range of files?

I have files named memOutput.X where X ranges from 0 to 47 in a directory. I want to see the line with the last occurrence of VmData in all these files. I can run grep VmData memOutput.0 | tail -1 ...
1
vote
3answers
45 views

text processing linux using grep awk or anything else

I want to replace in this string Wed Apr 10 06:44:10 UTC 2019 all whitespaces with comma and along with that trim off UTC part. What I have tried : var1="Wed Apr 10 06:44:10 UTC 2019" echo ${var// /,...
0
votes
1answer
45 views

get a specific line from in linux using grep

Hello I am new to linux and grep and awk commands. I am trying to get the number value from this string variable and then store it in another variable. var1="Version must be incremented on update. ...
2
votes
1answer
55 views

Cygwin 2.9.0 cat/tac Commands Fail on Large Files when Piping to grep -q -m1

I am seeing some odd behavior using Cygwin x64 2.9.0 on Windows 10 Pro x64. The command I am attempting to run is the following: tac <file> | grep -q -m1 -F "literal string" The above command ...
1
vote
2answers
537 views

Send email if script outputs string

I found this line: sh script.sh | grep 'NO' 2>&1 > grep.log && /usr/bin/mail -s "grep found something" m@mail.com < grep.log which will write the output of script.sh to grep.log ...
0
votes
2answers
165 views

Any way to avoid using `grep -v`

When performing a grep filtering across pipes, as in the following example, $ ps -ef | grep 24604 username 18660 24604 0 16:38 pts/3 00:00:00 ps -ef username 18661 24604 0 16:38 pts/3 ...
0
votes
1answer
227 views

Grep returns nothing

This is the grep command I used grep -ic address log* The output is 0. I know for a fact that there are more than 60 occurrences of the word address in the log file. But I still get 0. Now, I ...
1
vote
1answer
1k views

How can I use an iperf output and only grep Interval and Bandwidth?

I am trying to get the output from the command iperf -c 10.0.0.1 -t 3600 -i 2 And only need the Interval and bandwidth fields listed for the entire hour of logging. I haven't used grep or awk in ...
-1
votes
1answer
35 views

Apache Logs - identify IP that made series of specific requests

Given the following apache access log: 127.0.0.1 - - [04/May/2018:11:19:03 +0300] "GET /file1 HTTP/1.1" 200 ... 127.0.0.1 - - [04/May/2018:11:19:03 +0300] "GET /file1 HTTP/1.1" 200 ... 127.1.1.1 - - ...
-2
votes
1answer
26 views

finding a string among several zipped files (webapps)

We have to find a string, let's say "foobar" among several webapps. However, some webapps contain zipped files, eg log4j.jar. Therefore, grep -IR "foobar" /pathto/tomcatroot/ won't work, because of ...
1
vote
3answers
905 views

Grep last match from file

I'm running the following command against a log file and only wanting to get the last/latest match. Sometimes there may only be one match, other times there may be multiple, which is causing an issue ...
0
votes
1answer
318 views

grep multiple occurrences with intervening lines

I'd like to do the following: Given a file with many lines, several of which match a pattern, output the first matching line, the last matching line, and all the lines in between (I want them in ...
1
vote
1answer
597 views

Grep --only-match without new line

I want to use grep command to extract some strings from my data file. data file format a=1,b=2,c=3, a=4,b=5,c=6, I want the out format a=1,c=3, a=4,c=6, I tried the below command grep -Po 'a=.*?...
7
votes
5answers
5k views

Calculate sum of several sizes of files in Bash

I have list of files in a file, cache_temp. In file cache_temp: /home/maildir/mydomain.com/een/new/1491397868.M395935P76076.nm1.mydomain.com,S=1740,W=1777 /home/maildir/mydomain.com/een/new/...
1
vote
1answer
552 views

grep does not work in particular folder on centos?

It's a bit strange with the grep command. When I am in the mail folder, it always produces help text. At first, I thought I had wrong synxtax but it is working on its parent folder. What could be the ...
4
votes
2answers
504 views

How to show specific luns from lsscsi command?

I need to grep specific luns from the lsscsi command. For example: [root@e15l1 ~]# lsscsi 4 0 1 | awk '{print $1,$6}' | head [4:0:1:0] - [4:0:1:1] /dev/sdab [4:0:1:2] /dev/sdj [4:0:1:3] /dev/sdz [4:...
3
votes
2answers
4k views

Ansible yum update then email me the results

Writing a playbook to perform yum updates and then get an email from each server. I'd like the email to contain the changed contents of yum.log. IOW, I want the results of: grep [today's date] /var/...
0
votes
1answer
488 views

Grepping a single line from iftop

iftop -t -L1 -s1 Output: iftop -t -L1 -s1 | grep "Total send and receive rate:" Output: How can I grep just the "Total send and receive state:" line?
0
votes
1answer
487 views

Argument list too long with grep

Normally to search and replace a string in a selection of files, I would find with: grep -rl 'pattern' . This works fine unless you have a LOT of matches. Anyway, I was looking around and found a ...
1
vote
0answers
330 views

Legal Discovery - how to search .eml files for keywords and copy the results to another folder on macOS/Unix?

I've got a Kerio Connect mail server that saves all of it's emails in a relatively standard mail spool folder structure as raw .eml files. I've been tasked with performing a keyword search against ...
0
votes
1answer
990 views

Trying to do grep and sed from a file and push the output into a variable

Can we do grep and sed from a file and push the output into a variable grep "^/dev/disk/by-id/scsi-*" /tmp/disks.txt | sed '{'s/=.*//'}' Output would be like this: /dev/disk/by-id/scsi-...
-1
votes
1answer
686 views

Why grep doesn't work in the /usr/lib/systemd/system directory?

The other day I was on a RHEL7.1 system and I wanted to search for a specific word in the /usr/lib/systemd/system directory where all the systemd unit files are located. I used the grep command as ...
-1
votes
1answer
83 views

how do i remove local ip from list of ip addresses?

I have a variable that contains list of ips and i will like to remove the ip of the instance where the variable is set Please see below [root@ip-10-10-2-100 ~]# INSTANCE_IP=$(curl -s http://169.254....
-2
votes
1answer
93 views

Listing all packages, but without addional text

In this time I am working of project, what tell you, what software you have installer and what you can install. In this time I have problem with this command: grep -hn Package: /var/lib/apt/lists/* . ...
2
votes
1answer
38 views

How to signal the presence of a pattern via exit code, without altering STDOUT

I need to run cmd1. If and only if PATTERN is missing from its STDOUT, i need to run cmd2 too: cmd1 | grep "$PATTERN" || cmd2 But I'd like to see all output from cmd1, not just the lines that ...
0
votes
1answer
292 views

More elegant ps aux | grep [g]rep do not work

I am running the command: ps -ef | grep [p]ts/1 The result is: root 13820 1733 0 14:19 ? 00:00:00 sshd: root@pts/1 root 13822 13820 0 14:19 pts/1 00:00:00 -bash root 15847 ...
1
vote
0answers
513 views

Grep - Looking for non printable or higher range ascii characters

We faced an issue when someone copied a string from somewhere in one of the metadata xml files that contained ascii characters 239 (0xef), 191 (0xbf), 189 (0xbd) We fixed the problem in known file, ...
2
votes
3answers
4k views

Cron: only send mail if output contains string

Can I make cause cron to only send the email if the output (stderr) contains a certain string? I'm aware of this answer but the command I run doesn't distinguish between stdout/stderr, it always just ...
2
votes
1answer
10k views

Escaping special characters in grep regex

I am trying to run a grep regular expression on a file, where I have to exclude lines where "00" and "0" appear. I came up with this expression: grep -a -E \"stored\"\:\ \"\*123\*(?!00)[0-9]{2,5}\#\" ...

1
2 3 4 5 6