Questions tagged [grep]
grep is a command-line utility that is used for searching text.
745
questions
0
votes
1
answer
29
views
changing grep command --color from red to another color [duplicate]
I'm searching from the file using grep command with particular pattern,
sysadmin@localhost:~$ grep bash /etc/passwd
which return the output like below
root:x:0:0:root:/root:/bin/bash ...
0
votes
1
answer
64
views
caret character unexpected behaviour in regular expressions with grep
i was running grep commands from "William Shotts" regular expressions example.It seems,the caret character is not doing what it is supposed to do.
I have four test files with all the bin ...
1
vote
1
answer
47
views
Why doesn't the given command mask other lines? [duplicate]
Command: sudo find / -name miniedit.py -print | grep -i "miniedit" | tail -1
Output:
find: ‘/proc/10031/task/10031/net’: Invalid argument
find: ‘/proc/10031/net’: Invalid argument
find: ‘/...
4
votes
3
answers
610
views
Search for a "string" or "String with Spaces" recursively that may be a file- or directory-name or a text inside a file
I would like to search for the string rstudio (and its different possible combinations mentioned below) recursively starting from /.
In some locations, rstudio is a string inside another file (but ...
2
votes
2
answers
445
views
What grep pattern allows to print only one-word lines?
I want to print the lines with only one no-spaces subsequences of characters while use grep on the text.
title after grepping should to print title
the sentence after grepping should not print ...
4
votes
2
answers
714
views
Using grep to search for line that begins with a variable whose value is a dollar sign
I found a lot of very similar problems, but not exactly this.
I have a text file with the following contents (no repeats, fixed 4 characters per line):
A1234
G1234
$1234
M1234
I'm trying to use grep ...
-1
votes
2
answers
204
views
Filter RE in grep
The command that I have is:
grep -E '^ [0..9]'
The pattern that I have
24
-38.54270131
24
-38.54085331
24
-38.53603119
24
-38.53427780
24
-38.53396521
24
-38....
0
votes
2
answers
84
views
How can I search a file to see if it contains multiple patterns anywhere in the file?
I would like to be able to search a list of files for a list of patterns.
The file must contain all of the patterns and the patterns can be anywhere within the file.
Is there some way grep can do this ...
1
vote
1
answer
250
views
Search a particular string with grep
I want to search in a file with a particular string and show only those lines that exactly match with the string but that doesn't seem to work with grep -w.
This is just an example as I would be ...
0
votes
1
answer
175
views
How to use invert match regex in sed? like grep
How can I use invert match regex like grep -v ?
I want invernt
sed '/[Ss][0-9]*[Ee][0-9]*/d' ${Src}
like
grep -ev '[Ss][0-9]*[Ee][0-9]*' ${Src}
0
votes
1
answer
191
views
How to use variable in Find and grep command?
find command to get files have part of their names as date ($Y variable that has date in the script)
Y=(date -d "1 day ago" "+%Y-%m-%d")
find /log/bssuser/CDR/Postpaid_CDR_Log/ -...
0
votes
2
answers
62
views
Needing more efficient grep for excluding numerical value when in a string
I am grepping log files looking for results that show the output of 'queued 10' or higher.
Ex.
grep 'queued' *20231016* | grep -vE 'queued 1|queued 2|queued 3'
This works fine, however, is there a ...
0
votes
0
answers
26
views
Want to create a mask or formatting display for a file...where do I start?
on my computer I have plenty of text files which I use to configure an audio device (actually a Line6 guitar multieffect HX Stomp), and these files look like the example hereunder.
So there are lots ...
0
votes
1
answer
54
views
How to find a string in files, said string including line breaks, ", @
I know grep allows me to search for a string in files, however I did not manage to find the right method to search for the following string:
"snapshot3" : {
"@custom_name" : ...
0
votes
0
answers
106
views
How to get some lines before and after in log files using tail and grep? [duplicate]
How to get some lines before and after in log files using tail and grep ?
0
votes
1
answer
129
views
How can I determine the prematch and postmatch using egrep or ksh under linux
I am working on a issue at the office running on a linux system.
I would like to be able to either use egrep or ksh pattern matching to determine not only the matched string but I also need to be able ...
0
votes
0
answers
13
views
How to grep for an exact match of a string? [duplicate]
I want to find exact matches in a file that matches the string "1.2.0" (the numbers 1 and 2 and 0 with a single dot inbetween them). I am trying this as follows:
cat /my/file.log | grep &...
0
votes
1
answer
151
views
How to delete multiline string with grep
Let's say I have file.txt with following content (simplified for example. In real it's much more complex):
This line I DON'T want to remove \
common substring
This line I want to remove \
...
1
vote
1
answer
437
views
How can i fix Brightness adjustment on iMac 11.2 under Ubuntu 22.04.3 LTS ? The brightness still at his max
I'm new to Linux, and I don't know much about commands, I have an iMac 11.2 Intel® Core™ i5 CPU 680 @ 3.60GHz × 4, RAM 12 gb on which I installed Ubuntu 22.04.3 After solving the ventilation problem ...
0
votes
0
answers
15
views
Grep: How to search for an exact string of numbers in a file [duplicate]
So I have a file 2k6d.pqr with a list of coordinates and I am trying to find one particular one.
I type in
grep "-6.139 0.0488 1.4870" 2k6d.pqr
and it returns an error:
grep: invalid ...
0
votes
2
answers
162
views
Detect multiple files at subfolder containing specific string on Linux
I have multiple files of work.log at different subfolders need to detect two keyword Can't find file or Not pass by number
Direct path like :
/folder/Date/Job1/20190116_ADMtest_1/ADM.log
/folder/Date/...
1
vote
2
answers
35
views
find special characters in filenames and copy them into new folder. filenames may contain weird non ascii characters and special ones
I like to copy all files with special character "|" in filenames (not the pipe one) into a folder.
However, i have several problems cause filenames may include ascii and not ascii characters,...
5
votes
3
answers
1k
views
how can I get unique ip addresses from /var/log/auth.log?
How do I only show the unique IP addresses in /var/log/auth.log ?
I have a server getting hit constantly, and while I have set up fail2ban, the requests keep coming. So I started writing to ISPs to ...
0
votes
0
answers
25
views
Finding a file and ignoring the permission denied [duplicate]
I really need to find a file, and not only on my home directory
so I search from / but this gives a lot of "Permission denied" messages so I try
find / -type f -name a_file | grep -v "...
0
votes
0
answers
35
views
moving multiple files
i have a downloadsfolder that contains 9 items backup.sh ,bestanden.sh, tara.tar.gz, nmap.tar.bz2, demo11.zip, contract.pdf, cleaning.pdf, GNU-linux.jpg and video.mp4.
these have to get sorted in the ...
0
votes
1
answer
42
views
Why egrep outputs two blank lines but "redirecting to file" produces actual text
I'm using Ubuntu 20.04.4 with stock grep version 3.4.
I find something I cannot explain, please help.
[/dev/pts/0(xterm-256color) 2023-04-04 10:28:01 ERR:0]
[chj @Ub20cppdev ~/test]
$ cat input3l.csv
...
2
votes
2
answers
769
views
Running grep via GNU parallel
How can I make searches with grep on a large number of files run faster? My first attempt uses parallel (which could be improved or other approaches suggested).
The first grep simply gives the list ...
2
votes
3
answers
1k
views
Passing multiple file patterns to grep
I have a sequence of search patterns stored in a bash array (ptrn), which I want to pass to a grep command. How can I do it?
ptrn=("FN" "DS")
for fl in "$@"; do # ...
1
vote
1
answer
95
views
grep PCRE still greedy
I'm searching a multi-line text file and want to match a string from a certain word until the first match of another word:
start
word1
word1
word1
word1
end
word2
word2
word2
start
word3
word3
word3
...
0
votes
1
answer
73
views
How do I pipe grep commands with a "-" without it being interpreted as an option? [duplicate]
I'm using a Kali Linux distribution and I'm trying to learn how to use the | character for piping using grep. If I wanted to search the hashcat help file for what -a means for example, how would I do ...
0
votes
1
answer
80
views
How to extract channel names from YouTube subscription source file
I have an html source file of YouTube subscriptions, and want to extract just the /user/CHANNELNAME parts into a separate file.
The source file (browser > youtube.com > subscriptions > manage ...
-1
votes
1
answer
222
views
What's wrong with 'grep' command in Ubuntu-18.04.6?
I enjoyed 'grep' for decades but I left Linux years later and I came back again, finding 'grep' works different from before. I checked its usage from web and confirm my memory is not corrupted.
I am ...
0
votes
1
answer
63
views
How to Categorically Relocate Records Using Grep
I need to parse a file containing records beginning with a keyword and
selectively write those records to separate category files. After this
is done, the records that were extracted need to be ...
-3
votes
1
answer
455
views
Trying to pipe, redirect, or use `grep` or similar commands in a sftp environment
How can i limit the ls command output to display only the most recent X number of files created within a folder in a sftp environment ?
tail, grep, or > >> (redirect commands) are not ...
1
vote
1
answer
406
views
grep and awk commands not returning or storing output to the variable
I have a (users.csv) file containing a list of id's of all employees. I need is to loop through this file for each employee, search if it exists in backup.txt file using grep and store the output in a ...
-1
votes
1
answer
131
views
Trying to remove all text except for IPs, data is in a file I downloaded
This is what I normally use to normalize the data, but it is not working. I need to keep only the IPs, one IP per line, and everything else must go. I'm using this in an .sh shell script.
grep -oE '[...
0
votes
2
answers
142
views
why grep with regex command not working on Ubuntu
I wanted to know the packages which are installed and starting with mos then below command not working.
dpkg -l | grep ^mos*
0
votes
1
answer
173
views
How to grep on a file owned by nobody?
I have a /etc/openvpn/test.txt file with the following status and a single word content "test":
-rw-r--r-- 1 nobody root 173 Jan 25 21:48 test.txt
When I try to grep on it I get a ...
0
votes
1
answer
363
views
ps aux | grep command doesn't display categories
When I pipe to grep after a ps aux command it isn't showing the categories at the top of the list (USER, PID, %CPU, %MEM, etc) Is there something I can do about this?
ps aux --sort -rss | grep $USER | ...
1
vote
3
answers
220
views
Couldn't able to store a output of awk command
I have been trying to print git clone progress on more minimalistic way for my project.
Aim
Instead of printing a whole git clone output on screen
remote: Enumerating objects: 1845678, done.
...
0
votes
1
answer
75
views
Does grep and friends have a way to match strings as if shell file name globbing in stead of regex
Effectively I'm trying to search a text file containing "file names" and want to match as if shell file globbing were in effect.
Shell file globbing is much simpler than regular expressions, ...
2
votes
1
answer
326
views
Grep only until certain symbol
I try to grep some string and want grep to stop at a '+' symbol. The searched string could be "foo" or "foo+bar". Grep treats all findings no matter what comes after foo and the -w ...
2
votes
1
answer
569
views
Why "mount | grep sdb" displays no output, when "sdb" drive is a [swap] partition?
I'm learning about lsblk and mount commands in Ubuntu.
I'm using Linode vps server, 2CPU, 4GB ram with 1 additional block storage volume attached.
I have 2 questions related with this subject.
At ...
2
votes
1
answer
105
views
How to search output of help message of program (using e.g. grep)
I have a directory with executables and I want to search for a word in the output of the help messages of these executables, i.e. the text that is printed in the console after using the command ./...
9
votes
2
answers
783
views
Grep ignore array of patterns
Since I learned some bash syntax, I have being very enthusiastic about its use in daily life. A famous command is grep. In case one with to grep something but ignore several files, the commands below ...
0
votes
1
answer
52
views
How to list disk usage by directory, excluding certain output
I am trying to get a sense of disk usage and I want to exclude the ones I cannot access like this - any suggestions?
sudo du -h / --max-depth=1 | grep -v "cannot access"
Thanks.
2
votes
1
answer
662
views
How to log URL to a file only if it’s HTTP status code is 200?
I want to make a script so I can check if I can connect to several URL.
For example I do curl -i -L --silent URL | grep "HTTP/2 200" >> *.txt
I want to combine it with an if statement ...
1
vote
1
answer
363
views
chkrootkit says "grep --color=auto INFECTED," what should I do?
I just installed and ran chkrootkit for the first time and when I ran sudo chkrootkit | grep INFECTED, it returned ![user] 21342 pts/0 grep --color=auto INFECTED
I'm a complete novice at this and ...
0
votes
0
answers
273
views
How to replace URLs from html to a file using grep, sed or any common tools?
I'm trying to replace URLs of my conf file from a HTML file because sometimes the URLs get updated/changed. I need a simple script that can fetch the HTML & update/replace the URLs in my conf file....
0
votes
1
answer
565
views
How to exclude words using grep?
Instead of me chaining these like 10 times
cat /var/log/nginx/access.log | grep -v download | grep -v danger | grep -v "/visitor/return" | grep -v welcome | grep -v "GET / HTTP" | ...