Questions tagged [grep]

For questions pertaining to grep, a command-line tool for searching text patterns in files. Use this tag for questions about grep itself or questions about issues arising from using the grep command-line tool.

Filter by
Sorted by
Tagged with
1 vote
2 answers
92 views

Recursive pattern search - output formating: for each match file print out the specific file name "\n", line number, sentence matched "\n" in colors

I want a file content search command, under Linux so that: it will search on specified files, e.g: md, txt, htm. recursively from the folder and its subfolders, e.g: . the content search can be ...
user2718593's user avatar
0 votes
2 answers
51 views

grep for contents AFTER pattern in delimiter (serial number)

Say I have a file #cat serial SerialNumber : G5DBSTLAJ104949 I only want to know what words in print $3 appear after "SerialNumber" , I would much prefer that the output of ...
mark meddy's user avatar
-5 votes
0 answers
60 views

I need to sort files in recursive list, but there are some difficulties [closed]

I got some problems when I was doing the task: Output the first four elements of a recursive list of file names and attributes in the lib0 directory containing the string "ra", sort the ...
Kamilla_T's user avatar
4 votes
4 answers
615 views

Can I extract complete dates from file with grep command?

I need help using grep to extract a zoned date time from a file on a Linux system. Source file is a XML with the data below: <item start="20231010073000 +0100" stop="20231010100000 +...
aris's user avatar
  • 43
-1 votes
1 answer
50 views

Search for a string at proximity with another string?

Say I want to search for '123456789' and I want it to be near 'firstname'. Is there a way to do it? I've 0 logic to do this. Maybe piping greps could work? What kind of algorithm is best suited for ...
achhainsan's user avatar
0 votes
1 answer
74 views

Using grep with ps and column width specification

I'm trying to limit the column width of the command column when running a ps command, but also trying to pipe that output into a grep command. However, this is not working. This runs fine: ps -eo pid,...
risingTide's user avatar
0 votes
2 answers
20 views

Using find in order to detect a magento module

At magento routes are located in adminhtml/routes.xml each module has a folder named adminhtml with a file routes.xml each module has its own folder. In other words I have the following file structure:...
Dimitrios Desyllas's user avatar
0 votes
1 answer
30 views

Counting characters between grep searches

Is there a way I can use the grep command in conjunction with a series of other commands to find a character sequence (ie 'GAATTC' in a fasta file) and count how many characters are between each match?...
Alina's user avatar
  • 1
0 votes
0 answers
22 views

replace both filename and filename's content relying solely on pattern found on the name-of-the-file

I'd like to know if it's possible to replace both filename.ext and a matched pattern inside its content regarding a pattern founded on the filename itself using sed (and grep also, maybe?). Let me ...
dAllARA's user avatar
  • 13
3 votes
3 answers
82 views

How to recreate grep -f with awk

I have a large file with lots of unnecesarry info. I am only interested in section between edit and next and handle them as one entry. I manage to filter it down like this.... ' awk 'BEGIN {FS = &...
peti27's user avatar
  • 49
0 votes
1 answer
67 views

How to remove empty lines containing only ends of lines $?

I have a file: cat -E extracted_numbers.txt 11.47$ 0.32$ $ 1.37192$ -4.$ 7.$ 20.$ 13.$ $0. 15000$ 15000.$ $ 2.87$ $.6 47.$ $00. 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0....
Anna-Kat's user avatar
  • 115
0 votes
2 answers
32 views

How to grep logs with line break

I have a log file with the following structure, some logs will contain line breaks like [query-id=123] [query-id=123] contentA: 1. content 2. content 3. content [query-id=124] contentC [query-id=...
slow_mohammud's user avatar
2 votes
1 answer
129 views

Getting a short string from a long one without spaces

I have a file with a huge string without spaces in it (something like: "A":123,"B":456,"C":789...) I want to get X amount of chars before and after a specific value (like ...
Ran's user avatar
  • 125
2 votes
2 answers
232 views

A shorter way to list all packages matching a string

When I search for a list of packages, I usually use dpkg -l|grep string|cut -d" " -f3|xargs libdouble-conversion3:amd64 libestr0:amd64 libeval-closure-perl libio-stringy-perl libunistring2:...
rubo77's user avatar
  • 27.9k
0 votes
1 answer
28 views

Which portion of boot.log files are binary?

My system keeps seemingly randomly failing to boot after a kernel update. So I am reading logs to try to determine the cause of the issue. Here is one of the boot logs: $ sudo cat /var/log/boot.log.1 -...
li816's user avatar
  • 1
0 votes
2 answers
100 views

How to view a log file that's worth 10GB+?

The ways that I've thought of: If you get to reproduce the scenario in real time. Use tail -f application.log | tee /tmp/tailed_log But it's not sure that we'll get to reproduce the scenario in real ...
achhainsan's user avatar
2 votes
3 answers
90 views

Deleting files whose filenames match strings contained in a file

There is a text file, del.txt, containing a list of randomly-generated identifying strings, for example: 07ckv978yk0 HuinLBoZHcY _oR7ccXiunY I would like to delete any files whose filenames contain ...
Clayton's user avatar
  • 23
5 votes
5 answers
1k views

How can you, with bash, check all files in a directory to see which ones (if any) something was written to?

I ran a script which acts on multiple "people", and creates output and error files for each. let's say something like this: output_alice.txt error_alice.txt output_bob.txt error_bob.txt . . ....
abra's user avatar
  • 65
1 vote
1 answer
51 views

Regular expression to search contents that contain qr in it?

grep -rlw . -e '%QR%' I am doing something like this. Anything could be before QR and anything could be after QR. It could be nothing as well. I am searching for file names containing QR inside in ...
achhainsan's user avatar
2 votes
5 answers
325 views

Grep Multiple Pattern located in different lines and print in the same line

I'm trying to find a way to grep information in the file that located in the different lines and one of the pattern is contain pattern of date and time. below is the input unwantedtext unwantedtext ...
Ajie Pahlevi's user avatar
0 votes
1 answer
47 views

How to check logs greater than certain duration using grep?

grep -lw -e '0123456789' application.log_2023-07-* I want logs greater than 2023-07-*, how do I achieve it? Similar Question: grep particular log entry greater than specific time
achhainsan's user avatar
0 votes
2 answers
106 views

How to grep for the value of a variable inside a shell script?

I have 2 files: a file full of values I want to look for my source text file I wrote a short shell command to loop thru my list of values and grep against my source file. If it doesn't find the ...
Classified's user avatar
1 vote
4 answers
64 views

Find strings with several exclude-constraints on the beginning of the line

If I want to find all the "double-quoted" strings in files, I would use: grep -rnw . -e "\".*\"" but I want to exclude all the lines that begin with some text. For ...
Mark's user avatar
  • 713
0 votes
1 answer
51 views

Attempting to use a variable set from a read of a .csv file as the pattern to grep a second .csv file

I have two .csv files. The first file has a column of words. The second has two columns with the first column containing values that match one of the entries in the first file. I want to read the ...
Clay's user avatar
  • 1
-1 votes
1 answer
31 views

looking for paragraphs that contain every pattern in a list

I have a list of words in a file called pattern.txt. I need to search paragraphs of an input stream that contain ALL the patterns in the list. For a single pattern (foo) in paragraph I normally use ...
elmo's user avatar
  • 105
3 votes
1 answer
126 views

Save the output of earlier tailed logs to a file?

Is it possible to save the output of earlier tailed logs to a file? Steps to Reproduce this issue: tail -f application.log Ctrl+C to end the logs Save that output to a file now. I am assuming an ...
achhainsan's user avatar
2 votes
1 answer
147 views

What are the security implications of piping apt output compared to apt-get?

I tried to install all python3 packages so that I don't have to manually go to terminal and install one everytime. However due to some dependency issues apt refused to proceed: sonic@boomboom:~$ sudo ...
kseo6322's user avatar
0 votes
1 answer
26 views

bash non greedy grep between two phrases

I'm running a curl command to send data to a remote server. Part of the command is --trace-ascii which shows the full output for curl. I'm trying to grep this output so I only get the posted data. ...
Tom's user avatar
  • 479
0 votes
1 answer
45 views

Just as there is "locate" to "find". Is there a database for a faster "grep"?

locate (or rather, updatedb) is somewhat simple: it takes the output of find for the required paths (usually '/'), sorts it, and then compresses it with a front-compression tool (frcode), in which the ...
Sebastian Carlos's user avatar
0 votes
3 answers
98 views

How do I use grep, awk, or sed to get a substring of a line up until a string literal?

I am trying to process a text file and omit a certain string literal if it occurs at the end of the line. E.g.: Source: ABC 123 DEF, characters I don't want GHI, these characters are ok Desired ...
Evan Harmon's user avatar
0 votes
0 answers
37 views

OpenVPN using Luci (OpenWRT) ssh commands to get instances and enable/disable them

Hey all I have been researching how to go about doing this but I have not really found anything on it. What I am trying to do is, use SSH luci, get a list of all my OpenVPN instances: And be able to ...
StealthRT's user avatar
  • 131
3 votes
0 answers
159 views

In journalctl internal grep, is it possible to specify option to only output matched pattern?

I have the following journal messages: $ journalctl _COMM=kwin_wayland -o cat --since "-10s" ... kwin_screencast: Dropping a screencast frame because the compositor is slow kwin_screencast: ...
Ashark's user avatar
  • 769
0 votes
3 answers
71 views

Handling Space in Filename for sed command

I have 3 files: en.json, en 1.json and en 2.json. All of them have the below content { "ABC" : "/long_name", "DFG" : "/{long_name}" } I run ...
Aditya Naik's user avatar
0 votes
1 answer
42 views

How to grep n lines from the first occurence of a string in linux? [duplicate]

I need to share logs to developers. They keep asking for more logs. So, I'm wondering is there a way to grep 1000 or so lines after the first occurence of a string in linux.
achhainsan's user avatar
0 votes
1 answer
54 views

Limit 'grep -rnw . -e "string_to_search"' to only display filenames and not the contents?

grep -rnw . -e "string_to_search" This command takes the input string mentioned above and lists all the files in the current directory (indicated by a dot) that contain that string. The ...
zeeshanseikh's user avatar
0 votes
2 answers
69 views

Passing multiple includes that contain spaces to grep

I'm creating PowerShell and Bash scripts to standardise our usage of the former's Get-ChildItem and Select-String and the latter's grep. As part of the Bash script, I'm taking command-line arguments, ...
mythofechelon's user avatar
0 votes
1 answer
71 views

sudo cannot ls root owned files in /proc

I am on Debian 12 and I am trying to write a script to identify processes with certain inodes (from /proc/net/raw and /proc/net/packet). My original grep command is this (to get only the pid itself): ...
user avatar
1 vote
2 answers
71 views

How to find the most recent file that contains a string

I have a directory containing several files. I need to know the full path of only the most recent file that contains a certain string. This needs to work on macOS, and the directory path contains ...
Andrew Parks's user avatar
0 votes
2 answers
133 views

Remove exact line from file if present, leave the rest of lines; error-handling - how to go about it

I am not exactly sure how text processing should be done in a good way, so let me ask. I have this file: ~/.config/mpv/input.conf containing possibly other options as well as v disable. If I want to ...
Vlastimil Burián's user avatar
11 votes
1 answer
933 views

Use uniq to filter adjacent lines in pipeline

I'm trying to monitor theme changes using this command: dbus-monitor --session "interface='org.freedesktop.portal.Settings', member=SettingChanged" | grep -o "uint32 ." Output ...
Pavel Skipenes's user avatar
0 votes
1 answer
82 views

grep text only from files less than x size inside 7z

I have a 7z file that contains binary data and both large (>1Mb) and small (<1Mb) XML files. I want to find only the small XML files that contain a specific string. I've tried using zgrep, but ...
dsaizt's user avatar
  • 11
0 votes
1 answer
101 views

How to use the -E option of grep matching some variable name

We want to know about the correct method for matching some variable name(including its $ prefix) via using the grep -E option. It seems that this grep macthing function can only work with either no ...
lylklb's user avatar
  • 193
0 votes
1 answer
56 views

How to assign output of Grep in a Variable

I am trying to assign the output of grep in a variable . The below command provide me the correct output in a script str="DWMessStage-20230609-083501.xml__a6e27c1.4a73a37b.13.1889d3efa14.N7f9d....
Shuvra Maitra's user avatar
1 vote
2 answers
108 views

Grep not working - searching a file with a variable

I am trying to use grep to find the lines in a file that start with a specific variable I am defining. I know that you need to use double quotes with this command when searching with a variable, but ...
marissa's user avatar
  • 75
1 vote
4 answers
103 views

Find text files where the content is duplicated?

By mistake I appended (>>) rather than overwrote (>) the output from a script that processed thousands of files, but I only did it for about 20 % of the files (I ran 5 parallel instances of ...
d-b's user avatar
  • 1,713
0 votes
2 answers
67 views

Alternative to multiple greps [duplicate]

I am reading a list of outputs for pipewire in a shell script and looking for a specific entry. I don't know the exact name but I know the words that are in it. To find it I am using multiple greps ...
Justin Kachele's user avatar
0 votes
1 answer
28 views

Need help structuring a nested zgrep to produce a count

I've been assisting with some reporting at work, and am trying to get a unique count of different elements from some rather large log files that we are generating. So far, I've been able to run two ...
Barry's user avatar
  • 1
-2 votes
1 answer
145 views

What does "^ii" mean in the command grep -c "^ii"

Description To find the number of packages installed on the system, I tried the command dpkg -l | grep -c "^ii" (found here: How to show the number of installed packages). Questions It ...
Mon Les's user avatar
0 votes
1 answer
39 views

find content of files with other text and combination of xml tags, grep in grep?

I have a lot of files that match a grep 'xmltag' and 'subtag'. random xml needed_text random xml <xmltag> <subtag>content</subtag> </xmltag> I want to search for files that ...
Jvo's user avatar
  • 3
-1 votes
1 answer
79 views

How to remove characters after specific word using grep command in BBEDIT?

I have these data where I need to remove the extended URL from each website to make it, previously I used ^.+?(?=.com ) to remove the front line of characters. This time I need to remove the words ...
Anna's user avatar
  • 21

1
2 3 4 5
100