Questions tagged [grep]

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

Filter by
Sorted by
Tagged with
-1
votes
2answers
75 views

How do I grep a exact string from multiple files at the same time? [closed]

I have multiple files(text file) in a folder like below where the 1st file contains some paths as a string and the other with path+file_name. File1: # pwd /root/test # cat file1.txt /abc/bce/12345/...
0
votes
3answers
69 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 ...
1
vote
1answer
57 views

how to use grep and sed on adb logcat

I'm currently using grep in combination with adb logcat (android console api). Now I want to edit every line on the fly using sed in a pipe. However when using sed after grep the output becomes empty. ...
0
votes
0answers
28 views

Remove directory from a saving .gen file using grep command [duplicate]

I have used the grep command to match a pattern then the matching row has saved in a file. But when saved the result it's saved with the file directory. But I want to save only the row result not the ...
0
votes
1answer
38 views

how to select the specific string from 'ls' command console output?

I am newbie on linux os. My target is selecting files which have the specific string values in filenames on console mode This is my sample filename, filename : apnic-2016-02-01 condition : The first ...
0
votes
1answer
50 views

Cannot parse dst/src address

I created second ubuntu and then I installed openvpn then I wrote that command: sudo ss -tupln ׀ grep openvpn But was written Error: an inet prefix is expected rather than "׀". Cannot ...
0
votes
1answer
42 views

grep: option requires an argument — 'm' [duplicate]

I'm trying to grep a file in order to find a line containing this text: "-m". I've created this file to test this issue: echo "min-value: 2" >> test.txt echo "original-...
0
votes
0answers
17 views

Pass string with special character to grep as pattern [duplicate]

Trying to filter command output according pattern -p docker run --help |grep -F '-p' But grep treats it as -p as command option: grep: invalid option -- 'p' Usage: grep [OPTION]... PATTERNS [FILE]... ...
0
votes
0answers
19 views

I want to search with RETCODE & find 5 lines above beginning with NE : . Is there any way to do it with grep?

**NE : TALS1_TO** Report : +++ TALS1_TO 2021-01-25 02:02:18 O&M #806356831 %%/*1884960535 MML Session=1611550934*/MOD CELL:LOCALCELLID=2,CELLNAME="QALS12",ULEARFCNCFGIND=...
2
votes
1answer
117 views

Need to move files found using grep into a folder

As part of a University course, I'm trying to reclusively search for a string in a list of 500 files, and then copy those items found into a new folder. I can find the files without a problem using ...
2
votes
1answer
79 views

grep a string in a json output

I have an api-request that gives the output in the json form (form? layout? body? how do you say that?). See here: { "title": "Another Life (2019)", "...
0
votes
1answer
26 views

usage of grep command using the file includes the numeric sequences

I have a data file (seq_array) that includes the numeric sequences as follows: seq 640094400 60 640180770 I have also another file (data_file) that includes the data need to be extracted with respect ...
0
votes
1answer
73 views

How to grep all the strings which end with '.txt'

I need to find all the strings which end with '.txt' inside text file. I tried: grep 'txt$' myFile But it gives out whole lines, not only the strings which end with '.txt'
2
votes
1answer
47 views

How to make grep grab the first hit instead of the last

Let's say I have the following string: hello hi this test is test a test greeting test hello hello If I do grep -o "hi.*test", I will get: hi this test is test a test greeting test It ...
-3
votes
2answers
92 views

Delete files with same file name

I have a lot of *.srt file in my folder. The thing is I have some same file multiple times with a slightly different name.Like This: one_piece_001_US.srt one_piece_SPECIAL_001_US.srt one_piece_002_US....
0
votes
1answer
94 views

find files grep result then sort by file datetime modification

I have the following files **file_01.sh** abc bla bla function pause(){ bla foo function juliet(){ foo **file_02.sh** abc bla bla function pause(){ bla bla bla jjdjdjd foo function charlie(...
0
votes
1answer
118 views

Grep -v doesn't work when piping with locate

I have the following command: locate -br '^test.sh$' The output is: /home/cas/scripts/test.sh I want to have the path without the name of the file. So I did the following to remove test.sh from the ...
2
votes
2answers
503 views

find -exec grep in series with an inverted grep, find nested grep

I have the following three files **file_01.sh** GOOD_word bla bla BAD_word miao GOOD_word bau BAD_word GOOD_word foo **file_02.sh** GOOD_word yes GOOD_word bla bla BAD_word GOOD_word ...
0
votes
1answer
20 views

Sed insists on doing partial matches

Ok, consider this example file: #!/usr/bin/env bash cat > example_file.txt <<EOL group, , price 1, S_BRN_, 3.21 1, S_WBS_BRN_, 4.11 1, S_WBS_BRN, 1.22 2, S_BRN_WBS, 9.2 2, F_WBS_BRN_, 2.11 2, ...
1
vote
0answers
32 views

How can you use grep (or some similar program) to read all files as text files? [closed]

I am trying to find a string in a few files, however the files are currently read by Ubuntu as image files. How can I change this (in grep or in Ubuntu itself)?
0
votes
3answers
64 views

How to find files that user and group have the same permission [closed]

I would like to find the files that the user and the others have the same permissions. I tried ls -l and egrep but I don't know how I'll say that position 234 will be the same with position 567. ...
1
vote
0answers
28 views

grep without FILE parameter [duplicate]

What happens when FILE parameter is not given in grep ls folder1 folder2 new.txt new.cpp folder3 # -> folder 3 has all .cpp files with main grep -rl -e "int main" new.cpp folder3/one.cpp ...
2
votes
0answers
53 views

How to make iostat ignore snaps

I am trying to filter out snap loop devices from iostat, while preserving the color formatting of the output. I have tried the following: iostat -y 5 iostat -y 5|grep -v loop Neither option produce ...
0
votes
0answers
115 views

command history

Which is the most correct answer for this question: Write a one-line command that searches the last 50 commands that have been used for the term "find", and saves the result in history.txt ...
0
votes
0answers
38 views

matching single and double quotes in grep using -E [duplicate]

For practicing how grep works in Ubuntu terminal, I made one .txt file: '"..asdf_-_-..34'""'"'" jd8m***ns'''_**''x;';nn*?/...; ++..++ ./,/;]_+))(+_)((*+_":|.<"{}...
0
votes
1answer
58 views

How to replace every 2nd line sed

How to replace every 2nd line of a text file with another text file list of lines. Example: cat filea.txt I love Pink I love Blue I love Dogs I love MOMO cat bileb.txt I hate yello I hate white I ...
0
votes
1answer
81 views

How to replace a varying number of strings on lines that match patterns

File1 <filename1.txt> stringA string1 <filename2.txt> stringA string2 <filename2.txt> stringB string3 File2 <filename1.txt> words and symbols < $ stringA words and ...
0
votes
0answers
27 views

grep regular expression to remove packages [duplicate]

This is an unexpected result I get $ dpkg -l | grep linux-modules-nvidia-440-5.4.0-* rc linux-modules-nvidia-440-5.4.0-26-generic 5.4.0-26.30+2 amd64 ...
11
votes
7answers
2k views

Show all lines before a match

I want to show all lines before a match, not only 10, or 7, or 14 for example, as explained in How do I fetch lines before/after the grep result in bash?. How can I do it? It doesn't matter if the ...
0
votes
1answer
71 views

What does grep -cE “>” myfile.txt do?

I understand how to use grep; however, I am having trouble understanding the function of using ">" in my command?
0
votes
1answer
36 views

How to find out particular word “UNMAPPED” from several “UNMAPPED”

Hi I have a file which contains lines with word 'UNGROUPED' several times. But I want to extract the first line with 'UNGROUPED' and line with the word 'UNMAPPED' (present in file only once). Can I do ...
8
votes
2answers
409 views

How to use grep to search for options in a man page? [duplicate]

I want to search for specific options like -s, -f, -l in a manpage and display only the results that contain info on what those options do. I tried this command hoping that the single quotes would ...
1
vote
1answer
624 views

Does grep distinguish a variable and the $ regex?

I want to grep for a variable that has the string test, but I also want to make sure that it will only find test if that is the only word on a line. So, I tried this: string=test echo "test" ...
1
vote
2answers
113 views

How to copy files with certain permissions to directory

I'm trying to make a copy of files with read and write permissions for the owner only, and then redirect that file to a directory named $dirA. I tried to use this command: cp (ls -l ~| grep -type f-...
0
votes
1answer
41 views

Grep separates results by spaces

When using the following script #!/bin/bash cd ~/Downloads pdffiles=$(ls | grep .*\.pdf ) for pdf in $pdffiles do echo $pdf done The printed result is the name of the files separated by one on ...
2
votes
1answer
75 views

How do you list the folder permissions of only certain directories that follow a common pattern in a particular directory?

For example, in the /etc/ directory there are several files named rc0.d, rc1.d, rc2.d, rc3.d etc lets say you want to list the permissions or the sizes of these directories while ignoring other ...
1
vote
2answers
77 views

How do I get `abc.xyz.com` from `“127.0.0.1,abc.xyz.com”`?

I have a list in which data is in this format "127.0.0.1,abc.xyz.com" I want to get only abc.xyz.com without the IP address and double qoutes. How it can be done?
1
vote
1answer
187 views

Sort order of output when using sed and iterating in folder

I am using the following sed command to find a string in between patters for each file in a folder, files are named 01.txt, 02.txt etc.: sed -n '/PAT1/,/PAT2/{/PAT1/!{/PAT2/!p}}' * >> file but ...
0
votes
1answer
33 views

Command output is not redirected to file

I want to execute the following command, which is related to Rational ClearCase. The output of this command should be redirected to the file testout. Command rgy_check -vobs > testout Output ...
0
votes
1answer
260 views

ugrep PPA, snap or flatpack?

[Update: Please follow the instuctions in the accepted answer. A PPA, snap or flatpack is not necessary if you install from the source code.] Is there a PPA that has ugrep executables available for ...
0
votes
0answers
642 views

How to find, change attr -i and delete files

I need a command to find, chattr -i and rm -rf (delete) files I have a long list of files which I'm trying to delete using sudo find / | grep nginx | sudo xargs rm -rf and getting the following error:...
0
votes
2answers
1k views

Using grep to show k10temp-pci-00c3 CPU temp

I am using this to show my cpu temperature. echo CPU Temperature >> /home/andy/bin/HD_AND_CPU_TEMPS.txt sensors -f | grep "temp1" >> /home/andy/bin/HD_AND_CPU_TEMPS.txt geany /...
2
votes
4answers
990 views

How to search for a word in a file but also show the whole file along with the found word?

I am using Ubuntu 16.04. I want to search for a certain word, but I also want the whole file that contains the word to be outputted on the terminal so that I can see where in the file the word is ...
1
vote
1answer
64 views

Hyphen in egrep [duplicate]

I run the following command in bash: echo "#fastq-dump SRR3105676 --gzip -O my &" | egrep "-O" and I get grep: invalid option -- 'O' Usage: grep [OPTION]... PATTERNS [FILE]... ...
0
votes
0answers
31 views

Search in a file for a specific text in condition that other text does not exist

I have a text file bla.log that I want to search for a string "exception" and then print this exception in the screen only if 2 lines below this exception there is no string "freetouse&...
0
votes
2answers
263 views

Keep original spacing while doing replacements [AWK, SED, GREP, …]

I have two files which content are: File 1: ATOM 1 N LEU 1 -10.186 -21.276 -0.497 1.00 0.00 PROT ATOM 2 HT1 LEU 1 -10.773 -22.005 -0.843 1.00 0.00 PROT ...
2
votes
1answer
100 views

What does grouping in extended regular expressions mean?

I read that grouping treats an expression as a single unit. What does that mean? Furthermore, what does grep "\(grouping\)" file.txt or grep -E "(grouping)" file.txt do? I also ...
2
votes
2answers
162 views

Rename multiple files with variable extensions to remove beginning and end of filename

I have multiple files I need to rename as below: 5891_1_0_AD3884_ACTCTCGA_S10.bam 5891_1_0_AD3884_ACTCTCGA_S10.bam.bai 5891_1_AD3875_GAGCTTGT_S1.bam 5891_1_AD3875_GAGCTTGT_S1.bam.bai ...
2
votes
1answer
563 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
111 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

1
2 3 4 5
14