Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
-1 votes
1 answer
68 views

How do I find files of a certain extension(s) except in paths that contain certain strings and then print the result to a file?

Upon a little search, I came up with this command: > find . -type f \( -name "*.exe" \) | egrep -v > 'games_1|rei|games|tor|jogos|mods|text' > 1 What I wanted to do was find files ...
Nuno Fonseca's user avatar
0 votes
1 answer
69 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 ...
SpiderMan's user avatar
0 votes
1 answer
83 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 ...
S.Das's user avatar
  • 3
1 vote
1 answer
50 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: ‘/...
kesarling's user avatar
  • 121
4 votes
3 answers
637 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 ...
koustav_ch's user avatar
2 votes
3 answers
638 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 ...
palmasd1's user avatar
4 votes
2 answers
1k 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 ...
Aylox's user avatar
  • 43
0 votes
3 answers
229 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....
Another.Chemist's user avatar
0 votes
4 answers
253 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 ...
Barry Kimelman's user avatar
1 vote
1 answer
437 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 ...
sunny_hkhk's user avatar
0 votes
1 answer
345 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/ -...
Amany Abd Elmnem's user avatar
0 votes
1 answer
74 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" : ...
Vinz M's user avatar
  • 169
0 votes
0 answers
149 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 ?
indrajit narvekar's user avatar
0 votes
1 answer
152 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 ...
Barry Kimelman's user avatar
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 &...
Alex's user avatar
  • 865
0 votes
1 answer
186 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 \ ...
JaSON's user avatar
  • 123
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 ...
Pundarikaksha Kavipurapu's user avatar
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 ...
j0h's user avatar
  • 14.9k
3 votes
2 answers
1k 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 ...
Fatipati's user avatar
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 # ...
Fatipati's user avatar
0 votes
1 answer
88 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 ...
Eggwind's user avatar
-1 votes
1 answer
265 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 ...
Stan Huang at Taiwan's user avatar
0 votes
1 answer
67 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 ...
Paul_Capo's user avatar
1 vote
1 answer
460 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 ...
Haider Ali Syed's user avatar
0 votes
1 answer
479 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 | ...
Onizuka's user avatar
1 vote
3 answers
248 views

unable to store output of awk command

I am trying to print git clone progress in a minimalistic way for my project. Aim Instead of printing a whole git clone output on screen remote: Enumerating objects: 1845678, done. remote: ...
Eswar Reddy's user avatar
2 votes
1 answer
368 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 ...
diggidre's user avatar
  • 111
2 votes
1 answer
131 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 ./...
Kvothe's user avatar
  • 657
2 votes
1 answer
783 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 ...
bahsnub's user avatar
  • 21
0 votes
2 answers
757 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" | ...
code-8's user avatar
  • 195
1 vote
1 answer
230 views

How to grep certain attribute from openldap?

I am using openldap and usually I will use command ldapsearch uid=<ldap> + to check certain attribute and by running such command, it will produce full output for example : SASL/EXTERNAL ...
msmystic's user avatar
2 votes
1 answer
2k views

Grep output from application, show to screen and write to file?

I run an application and pipe the output to grep. This works. However, I wish to show the output on both screen and write to file. So I am piping the grep result to tee: ./app | grep something | tee ...
intrigued_66's user avatar
0 votes
1 answer
2k views

grep fails to find text in docx file

I cannot find the reason why grep cannot find the file with the word 'coomunities'. I used grep -ril --include=GLOB "coomunities" . Note: communities is on purpose mispelled. The file is a ...
asasa178's user avatar
  • 185
0 votes
1 answer
394 views

grep command to get file list with concatenated custom text

I am trying to list of files' names with custom text(my another command) with it. I am using below command: grep -rl --include=*.php --include=*.html --include=*.js 'ajax.googleapis.com/ajax/libs/...
Atul's user avatar
  • 241
0 votes
2 answers
137 views

Grep file for one target (+ next 3 lines) OR another target (just that line)

I want to search a file for two target strings. For the first target I wish to return that line and the 3 lines following it. For the second target string I want to return just the line containing the ...
user997112's user avatar
0 votes
0 answers
957 views

Searching text from a list in another file

Is there a grep-like program for Ubuntu that can search a text file, or batch of text files in a folder, for any occurances of words in another text file or a list like a csv file or an ods file or ...
gerardnfarrell's user avatar
0 votes
0 answers
252 views

bash script for grep with context

Am writing a bash script that uses grep to search phrases and prints them on terminal. I want the user to have the possibility of using the context options of grep (-C, -A, -B). I made an indexed ...
Fatipati's user avatar
2 votes
2 answers
1k views

Using grep to find tag and get arbitrary string after it

So I have this pattern, the whole thing is one line <img itemprop="image" class="hovered__image jsOpenGallery lazyload" data-src="//static.yellowpages.ca/ypca/ypui-6.65.0....
Krishna Raju's user avatar
6 votes
2 answers
1k views

How do I grep for arabic characters with diacritical marks?

I have large TXT files in arabic Tashkil and I'm trying to find lines that contain specific pattern mashkula with َ ً ُ ٌ ّ ْ ٍ , I've tried the following grep syntax: cat file.txt | grep "...
s3idani's user avatar
  • 363
0 votes
2 answers
531 views

bash: do not show the part of the line that is in the search terms of the grep command

For example I have a directory: /A/B/C/D/E/F/G.txt Not knowing a priori /E/F/G.txt, I need to isolate that part. For ease of example: echo '/A/B/C/D/E/F/G.txt' | grep -o '/A/B/C/D' Shows: /A/B/C/D ...
Mario Palumbo's user avatar
1 vote
1 answer
222 views

How to automatically open a file that has a dynamic filename

I'm trying to make an automation process, my workflow generates a file automatically, this file is named based on a timestamp and a public key. Example of the file name : UTC--2022-03-07T10-53-08....
EL-Mehdi Loukach's user avatar
-4 votes
1 answer
217 views

Can I make my own custom grep search tool?

I was trying to find a particular device on my machine. So I typed in lspci. This gave me a large list of items. Too large to constantly look through to see if my device is still attached or not. So I ...
ardoknow's user avatar
-4 votes
1 answer
779 views

find all files and folders which have specific owner/group with grep

In home/oracle I have many files and folders. I need 2 different codes to: find (show) all files and folders belongs to user "Jim" from group "app" Change user owner of all files ...
TimLer's user avatar
  • 95
0 votes
0 answers
46 views

Find specific numbers of capitalized words next to each other

Let's say I have a .txt file: Aaa Aaa Bbb Aaa Bbb Ccc I want to find the row that has one capitalized word, two capitalized words, and three capitalized words. So one grep to find Aaa, one grep to ...
Anders Begtorp's user avatar
6 votes
3 answers
3k views

How to check for a specific string with linebreaks in a file with grep?

I have a string variable in a bash script file as follows: string=" test1 test2 " and I want to check whether a file test.txt containts this specific string (including the linebreaks. i....
user56834's user avatar
  • 109
0 votes
3 answers
8k views

how to grep with multiple strings to find

I understand how to use grep in the simple form: <command that spits out text> | grep "text to find" I would like to be able to grep multiple different bits of text all at once. How ...
robotsfoundme's user avatar
4 votes
2 answers
6k views

Grep - How to suppress the "Is a directory" line?

When running grep 'string' * I'm getting the following messages: grep: some-directory: Is a directory grep: other-directory: Is a directory How to suppress those messages?
BlueSkies's user avatar
  • 2,175
0 votes
1 answer
2k views

When piping grep after a curl request, regex works very strange

Simple problem but really weird. When I make a curl request and do ... | grep -Po "^\d+$", it returns nothing eventhough there are 400+ results that should match. See below: #example snippet ...
Cas's user avatar
  • 582
1 vote
1 answer
149 views

Pattern Matching using Grep

I'm trying to find a specific value for my file heres a quick snippnet of it: PRODUCT_TYPE_NAME,PRODUCT_CLASS_NAME,PRODUCT_SUB_CLASS_NAME,PRODUCT_MINOR_CLASS_NAME,PRODUCT_COUNTRY_ORIGIN_NAME,...
Yunfei Chen's user avatar
1 vote
3 answers
611 views

How to delete part of a line and keep the rest using Bash?

Suppose that I have an output of lines like this: First name, Last name, 123456789(9 digits) GPA Class Major University How can I write some code to print the first 3 lines and only keep the ID ...
FancyName112's user avatar

1
2 3 4 5
8