Questions tagged [grep]
grep is a command-line tool for searching text patterns in files.
321
questions
-2
votes
0
answers
14
views
Search a pattern word from multiple files and concatenate whole lines in a new file
I have several data files. For example
sales.txt (the original file has 13 columns)
Date Unit $$ employee# abc def jkl mno pqr
Dec1 10 500 2 1 2 3 4 5
Dec2 12 450 3 6 7 8 9 10
Dec3 13 550 3 11 12 13 ...
0
votes
0
answers
15
views
Using systemd-run To Limit I/O on cPanel for Grep Command
When I run the grep command on Linux on my cPanel-based shared hosting account, I hit an I/O resource limit, it says on the cPanel. I tried to research how to limit resources on a command that I run ...
0
votes
0
answers
56
views
Replace a string from the cat output
I need to replace a string with the string which is mentioned in a file abcd.txt in all files in a folder.
For eg: I want to replace a string 'apple' with whatever the cat output of this file abcd.txt
...
1
vote
1
answer
18
views
Filter the output of locate not to show the Duplicates in rsnapshot
When I use locate on my server and the result is in my rsnapshot backup then I get all those duplicates.
I could use grep to filter out all rsnapshot files:
locate something_in_backup | grep -v /var/...
5
votes
3
answers
792
views
Best way to remove text from the beginning of a huge file
I have a huge MySQL backup file (from mysqldump) with the tables in alphabetical order. My restore failed and I want to pick up where I left off with the next table in the backup file. (I have ...
0
votes
1
answer
21
views
How can I highlight lines of a file that begin with abc and DO NOT end with xyz?
I have a daily script that retrieves hardware stats from all of my RHEL servers every night and saves them to a yyyymmdd_daily.log file. I have other scripts that I run against these files to extract ...
0
votes
2
answers
68
views
Zip all files returned from "grep-ril" command
I'm using grep -ril to be able to see all files that contain a certain string:
[user@machine]$ grep -ril "test string"
file1.log
file2.log
file3.log
file4.log
...
I then would like to zip ...
1
vote
0
answers
34
views
How to do sudo grep in a bash script?
I would like to check if the given ip address is already in the config file.
But /etc/ can only be accessed by root, and I'm running the a script as admin.
It seems I can't just do sudo
#!/bin/bash
...
0
votes
2
answers
51
views
I want to exclude specific words from the results when piping tail into grep
I am using "tail -f /var/log/fail2ban.log -f /var/log/ufw.log | grep -e Ban -e BLOCK -e ALLOW" (without the quotes) and it is working but I want to exclude the results that have the words ...
0
votes
1
answer
59
views
Regex does not work with grep
Why does this match
.*\/.+\/wp-admin.*404
[03/Sep/2021:18:58:29 +0200] "GET /up/wp-admin/install.php HTTP/1.1" 404 6197
regexr.com
But in grep it does not?
sudo grep -rh ".*\/.+\/wp-...
0
votes
1
answer
42
views
Linux cli pipeline command tail and grep
I am using tail to monitor a log file and using grep to filer the keyword.
tail -F somefile.log | grep "keyword" is working
tail -F somefile.log | awk '{print $4}' is working
but if to put ...
1
vote
1
answer
75
views
How get info into variables from command output
I am run nginx -V and get like this:
nginx version: nginx/1.18.0
built by gcc 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
built with OpenSSL 1.1.1f 31 Mar 2020
TLS SNI support enabled
configure arguments: --...
0
votes
1
answer
39
views
"grep" a group of lines
I am reviewing my mail traffic looking for large messages and sending these "finds" to the staff for removal or approval. Each message has four SMTP lines and I want extract just these ...
2
votes
1
answer
316
views
Extract a ids from text file
I have a text file live below
{
"data": {
"assigned-entity-id": null,
"assigned-entity-type": null,
"availability-domain": null,
"...
1
vote
2
answers
131
views
GREP multiple lines that are not next to each other
I have a text file that looks like this:
landlord: John Smith
has:
house: 0
flat: 5
available: 1
cheap: 0
quality: 1
landlord: Will Hall
has:
house: 3
flat: 4
available: 1
...
1
vote
1
answer
74
views
Format export using grep and awk
I would like to export data from zimbra server, but it's export data in every new lines, my command:
zmprov -l gaa -v domain.com | grep -e "zimbraForeignPrincipal: " -e "...
0
votes
1
answer
25
views
Find all words after specific string
So, here's the thing.
I have a file contains like this:
LOG=123 HEY=BRO FOO=BAR LOG=124
I need the value of LOG= and an output like this:
123
124
I already tried using this command:
echo "$LOG&...
-2
votes
2
answers
342
views
Linux Bash Scripting using grep sed and cut command to display ip address with port number
Can any one please help me
I need a output of "192.168.1.1#53" by using these 'grep' 'sed' and 'cut' command mandatory in linux bash scipting
in given below text.
;; Query time: 29 msec
;; ...
0
votes
1
answer
107
views
how to avoid grep output empty file
Using grep to print a keyword in a log to the output file
grep -i -n "application" /app/log1.log > L1.log
Now this gives results if it finds application in the log. But also results empty ...
0
votes
1
answer
2k
views
How to grep (Select-String) the output of curl (Invoke-WebRequest) in PowerShell
I'm trying to curl a website and grep it for a specific line in PowerShell. How can I do that?
Here's the equivalent of what I'm trying to do, but in BASH
user@host:~$ curl -s www.isxkcdshittytoday....
0
votes
0
answers
26
views
Summarize first column same field
I have some datas with URL's and used network data. I made a custom file with these data's and i stuck last one step.
What i have now:
sevroland.api.url.com 488
www.logstach.url.com 42725
...
0
votes
1
answer
254
views
How to change one line of code in a block of code from linux command line?
I have a change I need to make across multiple different sites and may need to make again in the future, so I'd like to put it in a shell script. Essentially I want to find a specific class block in a ...
1
vote
1
answer
918
views
CentOS command not found
When I login to my CentOS 7 Server I get a couple of errors.
Similar command is: 'tty'
bash: ls: command not found...
Similar command is: 'lz'
/usr/libexec/grepconf.sh: line 5: grep: command not found
...
0
votes
1
answer
102
views
How to tail server.log and grep multiple text combination? [closed]
The server log is too large, I would like to grep the logs which has "/API/login" and "/API/init" from the server log.
I'm able to use:
tail -f /server.log | grep -i "/API/...
0
votes
2
answers
613
views
Grep messages like trash - No such file or directory
my server was hacked, and I am now trying to locate all the "strange" files.
I am running:
find . -type f -name '*' | xargs grep -l "Mini Shell"
This command is helping me a lot ...
1
vote
1
answer
804
views
Scan IP range for SSL/TLS versions and vulnerabilities with legible/greppable output
I'm looking to find computers on the network that are using older versions of tls/ssl.
So far I've been using nmap's ssl-enum-ciphers and ssl-poodle scripts but the output isn't helpful as it shows ...
1
vote
1
answer
267
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
1
answer
737
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
1
answer
33
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
3
answers
253
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
1
answer
49
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
1
answer
97
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
2
answers
109
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
1
answer
76
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
1
answer
41
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
2
answers
62
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
0
answers
39
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 ...
1
vote
1
answer
1k
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
1
answer
101
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
1
answer
1k
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
2
answers
237
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
0
answers
41
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
1
answer
307
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
1
answer
136
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
2
answers
511
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
1
answer
884
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
3
answers
58
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
1
answer
87
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
1
answer
155
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
2
answers
952
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 ...