Questions tagged [grep]

grep is a command-line utility that is used for searching text.

Filter by
Sorted by
Tagged with
2 votes
2 answers
117 views

Using grep or find to get all files created in 2018 with "log" extension [closed]

Directory contains catalogs that have the following format: «20180201». I want to Get the list of all files created in 2018 with the "log" extension and their sizes. Can anyone explain me this?
dochi alshs's user avatar
11 votes
1 answer
13k views

Why should apt-key output not be parsed?

To validate that the docker gpg key is installed, I ran: sudo apt-key fingerprint 0EBFCD88 | grep "9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88" Which resulted in the following output:...
jfhr's user avatar
  • 213
0 votes
1 answer
297 views

How to search start and end with square bracket with multiple line

Text have [{hello=(1+2-0), hello2 = 1}] But are in two or three multiple lines when start with [ and end with ] are in different line How to extract like grep for this multiple line pattern?
BOMA's user avatar
  • 1
0 votes
1 answer
2k views

Creating/importing iptables rules to ufw

Thank you very much for your time in reviewing my issue. I am currently trying to convert the following iptables to ufw: iptables -A INPUT -p tcp -s 127.0.0.1 --destination-port 443 -j ACCEPT ...
p1r473's user avatar
  • 1
0 votes
0 answers
255 views

I can't get of this error and end up in tty mode after I start my system

/var/lib/dpkg/info/passwd.postinst: 21: grep: not found groupadd: group 'shadow' already exists Group ID 42 has been allocated for the shadow group. You have either used 42 yourself or created a ...
Skill Star's user avatar
3 votes
1 answer
1k views

How do I use string variable (which contains double quote) in grep

I have the following bash code: DNS_RECORD_NAME="\"_acme-challenge\"" linode-cli domains records-list 1020562 --pretty --json | grep '"name": $DNS_RECORD_NAME' The output should be like ...
Kalib Zen's user avatar
  • 155
1 vote
2 answers
1k views

find grep -E gives error: find: unknown predicate `-E'

I am running the command (on Ubuntu 18.04) find . \| grep -E "(\_\_pycache__\|\.pyc\|\.pyo$)" \| xargs rm -rf and I get the error find: unknown predicate '-E' I used to run this command on ...
Psionman's user avatar
  • 185
1 vote
1 answer
3k views

Filtering the lines which are greater than a percentage value

Hello i need to filter lines which are greater and equal than 85%. I need to filter according to Forward: Score line and end of the percentage of that line. Example file: Scores for this hit: >...
top5's user avatar
  • 13
0 votes
2 answers
2k views

How to arrange every n rows into columns using awk

I have a tab-separated data like this: a 2 b 3 c 4 d 6 e 8 f 9 g 10 h 11 i 12 ... My desired output should look like this: a 2 d 6 g 10 b 3 e 8 h 11 c 4 f 9 i 12 How can I do this, for instance ...
nsingh's user avatar
  • 13
1 vote
1 answer
1k views

I am trying to use the grep function in a script but it is not working, Although it is working in the terminal

I want to count the number of the G8LE word in my file so I opened a terminal and I used: grep -o -i G8LE C60_TAPC_GRM_box.gro | wc -l and it worked. I tried to write a script composed of many ...
Mohamed Abdelaal's user avatar
3 votes
2 answers
11k views

How to grep (print only) lines starting with uppercase-lowercase pattern?

I have a command that prints lines in format "Name:nickname". But since it is an output from getent, it also contains some lines which are not names. However, they all are either only uppercase or ...
Ferazhu's user avatar
  • 31
1 vote
2 answers
5k views

Process id is constantly changing, and it can't be killed with name

I'm working with Ubuntu 16 through SSH, and facing an issue with it. I want to kill the process but can't find a way because it keeps changing the PID every time. I'm using this command to check the ...
Div's user avatar
  • 117
0 votes
1 answer
668 views

Grep from nginx server files, but exclude www.domain.tld

I have a command in a bash script like this, to get me an array of all the domains on my webserver. domains=($(grep -rnw '/etc/nginx/sites-available/' -e 'server_name' -l | xargs grep -e 'server_name'...
Rando Hinn's user avatar
0 votes
0 answers
92 views

Find process started by Autostart (Redshift)

I've tried pgrep redshift, pgrep -f redshift, ps -ax | grep redshift, ps -elf | grep redshift, ps -ax -u root -U root | g redshift, systemctl | grep redshift all without finding the process, yet ...
alchemy's user avatar
  • 762
0 votes
1 answer
560 views

in VI mode i want copy particular specific lines from. log, .txt file

I have files which contain more than 2,00,000 lines in file i. e. abc.log file in that I want to copy line 600 to 750 and 40,000 to 60,000 in VI mode and paste new txt files
Pravin Gaddam's user avatar
0 votes
2 answers
626 views

how do I grep specific pattern from a Line using grep command?

to be more clear, I need to get the used space percentage (only the percentage without the other content in the line< of VOL (line 7) Using grep command*
haron's user avatar
  • 1
2 votes
1 answer
6k views

Using AWK, how to use tabs instead of Space as field seperator?

I have the following fields: Name<tab>City<tab>Phone Number If I use to awk, it returns only first name ("Muhammad"), when name is "Muhammad Tahir". How can I use awk with grep so it ...
Muhammad Tahir Qaiser's user avatar
2 votes
2 answers
1k views

The same string twice in the $PATH environmental variable

When I run $PATH on my terminal in Ubuntu 18.04.3, it displays the following: /home/ubuntu/bin:/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/...
BlueSkies's user avatar
  • 2,145
0 votes
1 answer
188 views

Search number list in multiple files and print

I am trying to find a few numbers listed in a file and their next +16 rows, from a bunch of files in a folder. Print or store output in a file, but the command is not displaying any output for i in ...
Ankur Bohra's user avatar
0 votes
2 answers
338 views

grep / sed / awk / count between two lines in file not whole file

I have this file on my laptop /etc/dbus-1/system.d/org.freedesktop.thermald.conf: <?xml version="1.0"?> <!--*-nxml-*--> <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus ...
WinEunuuchs2Unix's user avatar
0 votes
1 answer
302 views

grep error only when creating variable out of results

I'm parsing some json in bash. If I do this at a bash command prompt: cat junk|grep -Po '"loc":.*?[^\\]",' It returns: "loc": "21.0393,105.7666", But, if i do this to set a variable with the ...
Brian OHern's user avatar
0 votes
1 answer
1k views

How to list all files in a specific directory that starts with 'sh' including inode number in one line

Assuming I'm in the home directory I'm trying to list all the files in /etc to show all files that start with sh along with the inode number I tried the following: sudo find /etc -name 'sh*' # this ...
Ali Kleit's user avatar
  • 105
1 vote
2 answers
283 views

How to extract strings that appear more than once?

I want to extract from a file all the strings starting with 'File:' and ending with '.png'. I'm running the command grep -oE 'File.*\.png' list.txt But this gives me a single long string starting ...
pepesale's user avatar
1 vote
1 answer
625 views

More efficient way to find content of files within millions of files

We currently have a series of files ordered by date, by type and then individual XML files containing details, with the basic structure as: 2020-01-01/ FR_abc FR_abc_datetime_random.xml ...
neophytte's user avatar
  • 153
12 votes
1 answer
5k views

How to pass list of names to be searched by grep using xargs?

I have a text file containing names (nameslist.txt) and I want to read them using cat and pipe the result with xargs to a grep command, so that grep checks the existence of each name that it receives ...
arash deilami's user avatar
1 vote
1 answer
117 views

service --status-all | grep <anything> always returns [ ? ] entries [duplicate]

Trying to get the state of a service that is running (or not). I use service --status-all | grep <service> and no matter what I enter for <service>, I always get: [ + ] <service I ...
chow's user avatar
  • 225
0 votes
3 answers
1k views

How to copy/move files with more than two keywords

I have a file list like this (long list, not all): And I want to filter the files with keywords "QM" and ".h5", so I type ls|grep "QM"|grep "h5" and it shows these (what I need) So basically I want ...
Negrito's user avatar
  • 794
0 votes
2 answers
678 views

How to calculate average of 2nd field from files?

I have a file and it consists of two fields. The first field format is "%FT%T". Sample data: 2019-01-01T00:00:00 4.8 2019-01-01T01:00:00 5.1 2019-01-01T02:00:00 5.4 2019-01-01T03:00:00 5.7 2019-...
chess_freak's user avatar
0 votes
0 answers
42 views

Search a list of unic values in another list. Linux

Im trying filter only specific values in a very long list with repeated values. The long list: ASUR B 356.660 FEMSA UBD 181.670 AMX L 15.060 ASUR B 356.290 ASUR B 356.480 WALMEX * 56.510 ...
Salvador Guram's user avatar
1 vote
1 answer
5k views

Grep the contents of a file for contents from another file one at a time

I am using grep -o <string> <filename> | wc -l to count the number of times <string> occurs in the file. I now need to extend this such that the string is from a list of items in ...
stranksa's user avatar
0 votes
1 answer
1k views

script to copy multiple files from multiple directories to one of the folder/directory

I'm having five different directories in the home path which contain some files in all directories, as shown below. home/dir1 contains: abc121219.txt kucj.txt gtuj120518.txt gdkmcg.txt such.txt ...
Pravin Gaddam's user avatar
3 votes
2 answers
453 views

How to insert filename by changing format to same file?

I have many files. File format is year(4-digit)month(2-digit)day(2-digit) Sample filenames: 20150101.txt 20150102.txt Content of sample filenames 00:00:13 -> 001528 I want to extract data as ...
chess_freak's user avatar
3 votes
2 answers
5k views

how to find or list file and directories which having size more than 100mb

How to find or list file directories which having size more than 100 MB I'm using du -sh* to get the size of file but my system don't have permission
Pravin Gaddam's user avatar
6 votes
2 answers
5k views

How to grep words from a single string matching a pattern?

Will anyone guide me to grep only words containing pattern _ARA from the below single string. String: LINK:['IM219MIR_ARA1','IM18Q4_ARA1','SM18Q4_ARA1','IM18PLANNING_ARA1','IM118Q4DYNVA_ARA1','...
ptmjyothish's user avatar
4 votes
2 answers
2k views

How to read .json to output an specific number?

Hello I've been using this: curl -s "http://api.openweathermap.org/data/2.5/forecast?id=6361046&APPID=6be5e3a6e62680c28044791e8fc7b568&units=metric" -o ~/.cache/weather.json to write a ...
Wonky's user avatar
  • 321
1 vote
2 answers
362 views

How to grep for "STRING1" but skip if the line contains "STRING2"?

I want to search for "STRING1" using grep but to skip if the line contains "STRING2". How can I do it?
BlueSkies's user avatar
  • 2,145
3 votes
1 answer
363 views

Unzip a .zip file to all directories that contain a .php file that contains the text “house” inside?

How to unzip a .zip file to all directories that contain a .php file that contains the text "house" inside? Something like: grep -rl --include='index.php' 'house' /directory/path/of_the_index_file* |...
Jaro's user avatar
  • 33
1 vote
3 answers
727 views

How to grep lines which doesn't contain words with certain character except certain instances of words with that character

I have very long file.txt which, among other hundreds of lines, contains lot of lines like these ones: CD H1 CD H123 CD C2 CD D1 CD H2FOO CD HXY I want file which doesn't contain lines with ...
multipole's user avatar
  • 131
0 votes
0 answers
444 views

Grep search files using a list of keywords

I've build this command up from searching questions here. It works if I supply the keyword manually, e.g. while read line; do grep -wFrIin "keyword" --exclude-dir={.git,target} --include=\*.{java,ts,...
TungstenX's user avatar
  • 185
2 votes
1 answer
356 views

How to list also two lines after a grep match?

grep 'STRING' filename searches the file for STRING and lists the lines that contain a match. How can I also list two lines that follow the match?
BlueSkies's user avatar
  • 2,145
1 vote
3 answers
1k views

how to grep two paragraph from file?

i have file "test_file.txt". My output must contains all"IP ADDRESS" and "MONTHS OF 2017" from file test_file.txt. Server$ Server$cat test_file.txt IP ADDRESS: 1. 172.17.17.17 2. 172.17.17.18 3. ...
Milan's user avatar
  • 13
0 votes
1 answer
517 views

grep a word/number between two specific characters

When you ping you will get the ip between () , for e.g : (10.10.10.10) and after the ip there are (number) for e.g : (10.10.10.10) 56(84) so how i can get the ip that is between the () ? and without ...
maksim lev's user avatar
7 votes
1 answer
20k views

List certain installed packages

I am trying to see whether I have installed certain packages. I figured this would work apt-get list --installed | grep "xxx" but it doesn't. Any ideas?
Centaro's user avatar
  • 71
0 votes
0 answers
525 views

How to compare two files with without it doing it line-by-line or ignoring words it has already seen before? (Bash Linux)

So I am trying to compare two files. text1.txt and text2.txt and put the difference between the two files in the file text3.txt My issue is that I cannot find a way to make it eighter not check line-...
Bart The Bart's user avatar
0 votes
1 answer
116 views

I need to pull email size for each email in a sendmail log, then total them up with the total size and total number of emails

The size is simple to find after size= i can find the size and put it to a file but removing everything but the numbers and then summing it with the total numbers all in one file is just not coming ...
Thomas Hamilton's user avatar
2 votes
1 answer
8k views

Using grep and sed to make changes to a config.yaml file

I have a config.yaml file which i want to edit or make changes to using a bash script. So i got a command using grep and sed which gives me the desired changes , but the problem is that when i apply ...
Prototype's user avatar
  • 129
6 votes
4 answers
1k views

Count number of different name in a file

I want to count the number of different name in a text file of this presentation: 2008 girl Avah 2009 girl Avah 2008 girl Carleigh 2011 girl Kenley 2012 boy Joseph 2013 boy Joseph 2014 boy Isaac 2014 ...
John Baptist's user avatar
3 votes
2 answers
663 views

How to modify a file if file contain numbers that begin with '+1'

I am transferring an Android SMS database to my iPhone manually without restoring. Because of the number format of +1562... the iPhone does not recognize the format and creates a new text thread. I ...
abolodo's user avatar
  • 31
0 votes
1 answer
110 views

Count findings of string in folders

I have a folder with .tex files and want to find how many TODOs there are in all files. Currently, I'm doing this: grep -r "TODO" chapters/*.tex | wc -l This gives me each line that has (at least) ...
user1406177's user avatar
2 votes
1 answer
3k views

Bash, grep, whole line as variable

Issue How can I store whole line output from grep as 1 variable, not for every string. Example (I need just 3 variables, whole lines). user@local:~/bin/kb$ grep -E '##.*bash.*file.*add' bash.kb ## ...
genderbee's user avatar
  • 850

1 2 3
4
5
15