Questions tagged [grep]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
32 views

Asterisk is not working in Ubuntu 20.04 [duplicate]

After switching from 18.04 to 20.04, I noticed that the asterisk thing doesn't work. For example: If I want to remove all nvidia packages, I type in sudo apt remove *nvidia* and apt removes any ...
0
votes
2answers
41 views

Can i use grep to search words on the content that i already have in terminal [duplicate]

I am new here and in the Linux world. So i am wondering if it is possible to search for a word in the content that i already have in my terminal. Thanks in advance
0
votes
1answer
22 views

How do i apply a command to each line in the output from pipe and add all those numbers?

I have a command that outputs the following file sizes in multiple lines: 32G 16K 2M and the requirement is to convert them into bytes by using the command numfmt and add all the bytes: ...
3
votes
2answers
105 views

Differences between grep, fgrep and egrep

What are the differences between grep, fgrep and egrep? What are some examples of using them differently?
1
vote
2answers
38 views

piping grep to another grep doesn't work as expected

I'm using grep on Ubuntu Desktop 20.04. I want to get player movements from gnuchess game by using grep each turn. The first command i used is this : gnuchess -mq | grep -a "Black ([0-9][0-9]*) : [...
1
vote
2answers
44 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?
1
vote
1answer
128 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: ...
0
votes
0answers
45 views

need help- awk solution? - FileA string search column -> for new search in FileB ->grep

Here my problem : I have two files fileA and fileB, and a folder that contains the test files with component names I have to extract column1 from fileA if another column (can varie) contains ...
0
votes
1answer
24 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?
0
votes
1answer
57 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 ...
0
votes
0answers
44 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 ...
0
votes
1answer
33 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 ...
1
vote
2answers
97 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 ...
1
vote
1answer
125 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: >...
0
votes
2answers
40 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 ...
1
vote
1answer
79 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 ...
1
vote
2answers
130 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 ...
0
votes
2answers
88 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 ...
0
votes
1answer
34 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'...
0
votes
0answers
32 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 ...
0
votes
1answer
34 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
0
votes
0answers
36 views

grep a series of amino acid residues?

I have a large PDB file. I would like to grep lines with a sequence of amino acids from it. A part of the file is given below. I want a separate file (dat or txt) with th sequence ex. ALA-LEU-THR-ARG. ...
0
votes
2answers
27 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*
1
vote
1answer
77 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 ...
2
votes
2answers
133 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/...
0
votes
1answer
38 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 ...
0
votes
2answers
133 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 ...
0
votes
1answer
79 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 ...
0
votes
1answer
32 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 ...
1
vote
2answers
68 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 ...
1
vote
1answer
71 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 ...
9
votes
1answer
406 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 ...
1
vote
1answer
45 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 ...
0
votes
3answers
124 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 ...
0
votes
2answers
99 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-...
0
votes
0answers
33 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 ...
1
vote
1answer
62 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 ...
-1
votes
1answer
48 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 ...
3
votes
2answers
170 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 ...
1
vote
2answers
269 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
6
votes
2answers
649 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','...
4
votes
2answers
698 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 ...
1
vote
2answers
221 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?
2
votes
1answer
87 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* |...
1
vote
3answers
80 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 ...
0
votes
0answers
97 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,...
2
votes
1answer
31 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?
1
vote
3answers
175 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. ...
0
votes
1answer
31 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 ...
2
votes
1answer
2k 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? Thanks in advance

1
2 3 4 5
13