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
votes
0answers
30 views

Getting so libs strings and sort in GNU/Linux bash

i am trying to get in order the strings from the system base libraries First the commands i use for this : «reset» is a command for clean the screen «strings is a command for gather information from /...
3
votes
3answers
212 views

Extract text starting at specific category header to next category header from a text file

I have a TOML file in the following format (categories may have any name, the sequential numbering is just an example and not guaranteed): [CATEGORY_1] A=1 B=2 [CATEGORY_2] C=3 D=4 E=5 ... [...
3
votes
1answer
125 views

How to match two patterns using OR?

I need to use grep and awk in order to match two types of patterns but I cannot figure out the syntax. My file has values such as: sample1,gicode1,123,4541,221,3661,Sodalis sp.1 sample2,gicode1,123,...
2
votes
4answers
345 views

Matching Repeating Pattern Using Regex

Let's say I have a file like following 1,2,3-5,6 1,2,3-5,6, 1 1-3 1,2,3-,4,5-7 1,2,3-,4,5-7, 1,2,-3,4,5 1,2,-,3,4 1,2,,,3,4 ,1,2,3 Only combination of following rules should be considered as valid: ...
-1
votes
2answers
68 views

passing exclude and include file type extensions to grep

I have two variables, passed as command line arguments to a bash function, containing exclude and include information on file type extension, using comma as delimiter. excl="el" excl="...
-1
votes
2answers
54 views

Grep first word of a line from a file

So I have a file.txt like John john@gmail.com Mary mary@gmail.com but I also have Pickethunter123 timmy@gmail.com XPC61 roger@gmail.com GeorgeBushSucks michael@gmail.com and I have a list of English ...
4
votes
1answer
100 views

Search, separate, and purge txt values

What's really tripping me about this is the quote marks. I have a file.txt with lines like: {"a":"town, state, country","e":["john@company.com"],"n":&...
0
votes
2answers
28 views

Grep line based on first column

I have files in the xyz file format like this: 55 FINAL HEAT OF FORMATION = 0.000000 C -1.602726 0.220926 0.289897 C -1.486393 1.490851 -0.581098 C -0.269002 2....
0
votes
0answers
28 views

grep : sort strings CASE INSENSITIVE which end or begin with specific letter

i have a file names.txt, now i want to store all the names that start with D in another file startWithD.txt and store all the names that end with E in another file endsWithE.txt (the search being case-...
1
vote
1answer
77 views

Grep regex to find lines with something other than letters/numbers/dash

I need a regex that will get me in file.txt lines which have something other than just letters or/and numbers and dashes. file.txt looks like this zigzag-p 100-ig inter-op But it has like ...
0
votes
1answer
103 views

Why does “grep foo bar” print “grep: bar: Is a directory” instead of printing any filenames in bar/ that match the pattern “foo”?

The man page for grep describes the -d ACTION option as follows: If an input file is a directory, use ACTION to process it. By default, ACTION is read, i.e., read directories just as if they were ...
1
vote
0answers
27 views

How to filter for only unique errors in multiple logs using grep?

I am trying to use the following pattern on Ubuntu: grep -Eri "warning|error|critical|severe|fatal" --color=auto to find relevant errors in many different .log files recursively in /var/log ...
3
votes
2answers
224 views

How to grep for a pattern that looks like an option? [duplicate]

m@m-VirtualBox:~$ man netstat | grep "-t" grep: invalid option -- 't' Usage: grep [OPTION]... PATTERNS [FILE]... Try 'grep --help' for more information. I don't want to pass the -t option ...
0
votes
2answers
55 views

Grep String that contains only two number

I have a Sample file which contains strings as GABCDF64V3 HABDDF61WE KABSDF6WER HAADYF6WE2 I need only values which strings contain two numbers only(Anywhere in the string), Means output should be ...
0
votes
0answers
42 views

how to record count a .csv file combining two columns

I have a requirement to capture record count for a .csv file, but here is a catch The .csv file is having total 48 columns column 1 - DATE (yyyy-mm-dd) , column 2 - TIME (Time stamp - hh24:mi:ss) ...
0
votes
5answers
69 views

How to grep text between two commas

i have a string in text file, i want to grep the email address but it is not working 26,2,12,1,1,0,1,0,12,20,648130864.573339,,"iCloud - Device Locator",,,69FFBE2F-6626-4A4B-8A78-...
1
vote
1answer
32 views

How to find a file with a given string in several directories?

I tried: grep "6 0 1 1 0.4154" /media/linux/DATADISK/* but it does not search in subdirectories of the directory DATADISK.
-1
votes
1answer
37 views

How to grep lines NOT starting with '##' without excluding lines starting with '#'

I have a text file where some lines start with ## and others with #. Some lines have neither of the above. I'd like to return all lines EXCEPT those starting with ##. Running grep "^[^##]" ...
0
votes
2answers
46 views

grep string from 1 to specific line

I am working on Linux and I'm running the following: $ ls -t postgresq*.log | head -n1 | xargs grep "ALTER USER"   < pg_user 2021-07-15 05:03:41.609 EDT > LOG:  statement: ALTER USER ...
0
votes
2answers
40 views

Check for line in text bash

This is a really stupid question but I can't find an answer anywhere. So I have a command that prints out lines of text like this: htop kvantum alacritty And I need to check for a line, not a ...
1
vote
2answers
47 views

Complicated search and replace in Vim or Sed

I have the following (yanked from my register to retain formatting, as it's probably the reason I'm here): <li><span>Concrete Patching (</span><span style="overflow: ...
0
votes
2answers
46 views

How to find content in Curly braces

I have a file: [{ abc def 123 }] [{ abc 456 789 }] var="789" i want find (grep sed ...) $var return results Curly braces : { abc ...
5
votes
3answers
320 views

I can't grep tmux ls output when no tmux server is running

I'm trying to find a way to check if tmux server is running or not in order to update my zsh prompt with that information. when tmux server is alive > tmux ls 0: 1 windows (created Sat Jul 10 13:47:...
0
votes
1answer
33 views

How to search for a specific byte in all files in a directory?

I have a bunch of files in mixed encodings of utf8 and ISO8859-1. The only real difference between them is 4 characters which I want to convert to utf8. I'll do that manually, all I need is to find ...
3
votes
1answer
80 views

How to get apropos to show only executable programs/shell commands?

Most of the times when I use apropos I don't care about system calls, library calls etc — I'm just trying to find a command I forgot the name of. Is there a way to trim down the output of apropos to ...
0
votes
2answers
79 views

Append Lines on Unix from File1, File2 into File3 based on the Column value in a specific sort order

I have been searching over the web for a week now and I can't seem to find any solution that works for the scenario I have. I have two files. File1 contains a number of columns but the last column is ...
0
votes
2answers
36 views

Match exact string ignoring special characters like hyphen

I have a text file like Data1 AppFlows Data2 AppFlows-1 If I do grep '\bAppFlows\b' file It prints both the lines, which means we don't seem to consider - in the boundary I looked around and found ...
-1
votes
2answers
33 views

Check if the second integer of a line in a file matches

I have a file with the below format of entries. $ cat mw.hosts host23v0242 USER=wsadmin MOUNTPOINT=/web server21v0243 USER=wsadmin ...
1
vote
1answer
59 views

Get output from intel_gpu_top as variable in bash

Normally using grep would do the trick sudo intel_gpu_top | grep xyz But in this case intel_gpu_top is like htop and runs constantly. How would i extract the needed information inside a bash script? ...
1
vote
1answer
40 views

How read file paths mentioned in a text file inside a Korn shell script?

I am writing a script to read multiple log files and find lines with a specific string. However I am getting an error when trying to egrep/grep on the file. I have a file that has the names of the log ...
0
votes
2answers
75 views

grep/awk for matching both strings

I need to use an if statement that is true only if "is loaded" AND "is running" occur in a service status command output: $groupservice status service 1 is loaded service 2 is ...
0
votes
1answer
54 views

How do I grep files with .mp3 but not .mp3.RegFr? [closed]

I have files ABC.mp3, ABC.mp3.RegFr. I want to grep files with .mp3 and not .mp3.RegFr. Can anybody help?
9
votes
3answers
442 views

How to search for multiline text files containing a set of words (e.g., AAA & (BBB | CCC) & ~DD)?

I need to find the files that fulfill relatively complex condition. For example, I want to find all files that fulfill all below conditions: does contain word AAAA does contain word BBB or CCCCC (may ...
2
votes
2answers
118 views

Search for two alternative version numbers using “grep”

I have a file file.txt c-hcos-49.84.202106221 c-hcos-4.4.9-open c-hcos-4.9.9-open I want to grep lines that contain either 49 or 4.9 immediately after the string hcos-. I used cat file.txt| grep '...
-1
votes
1answer
90 views

Output of this command Linux [closed]

Please do anyone has an idea about the output of this command , I have googled a lot about it but I can't find anything useful find . -type f -exec grep -H PATH {} \; Thanks in advance
0
votes
1answer
64 views

Is possible for grep to see the exact word? [duplicate]

Is possible for grep, or egrep to see the exact word? See this example: those are my groups groups floppy audio video cdrom games plugdev power netdev scanner users I want to see only power, but ...
0
votes
2answers
37 views

Add headers to lines according to column

I have the following input a b danny c d joe 1 4 danny d 5 dana e f joe t 4 dana I would like to sort by last column, and add it as a header to each group of lines. The output should be (order of ...
0
votes
0answers
61 views

grep returns empty response

I have below code which reads file ctakes-backlog-new.lst line by line and grep full matching string from file without_symlink.lst and loads the result in ctakes-backlog-new.lst. Both files are sorted....
1
vote
2answers
71 views

search multiple files for a string on AIX

I was trying to search multiple files for a string like this. Using AIX if this matters. grep -r "gap" /u/user/.History/ /u/user/.History/server/user: /u/user/.History/server/user: This ...
2
votes
2answers
45 views

grep (or sed?): skip a specified number of lines before looking for matches

I'm working with huge log files that accumulate over days that I can't truncate/rotate but need to parse new entries hourly. I've been using grep to grab entries with a specific string then counting ...
0
votes
0answers
21 views

how to find the lines by ignoring word sequence, in Linux? [duplicate]

I am trying to ignore the order of the words and searching for the line in one file which has below pattern for example : My Name is ABC. Now I want to change the sequence of words in the same ...
1
vote
1answer
14 views

how to logresolve httpd log file to /dev/null and tail it?

I would like to watch traffic live (httpd log activity) , I currently use tail -f /var/www/access.log It works fine , its live, however just want to convert ip address to hostnames, i dont want to ...
2
votes
6answers
408 views

How do I extract the digits from a line and save it into a variable?

I feel like this is a really easy question, and when I Google, I find lots of answers for part of the problem, but when I try to put them together, it doesn't work and I can't figure out why. Here's ...
1
vote
0answers
46 views

Bash file descriptor redirection mystery [duplicate]

This is a mystery encountered at work today. Note that this behavior seems to be specific to a binary that I do not know the contents of, but any ideas as to how this phenomenon could occur would be ...
0
votes
2answers
69 views

How to make Grep non-greedy

I got a file so something like: helsoidfiejoih heye heye hey me is hi The file can have any number of lines or characters in it the point is that it is a text file of some sort. Now the I need to ...
0
votes
4answers
749 views

Grep and Cut command in linux

I have a csv file with loads of data. I wish to cut the 9th column for values >=1 and then use grep to display full rows that match. Sample format: ABC,XYZ,RTY,CREAM,FRANCE,170019,ST REMY CREME,...
0
votes
1answer
106 views

grep -v not working inside shell script

I have this line inside my shell script: tomcatPID=$(ps -ef | grep tomcat | grep $TOMCAT_ACCOUNT | grep -v grep | grep -v restart | awk '{print $2}') I made sure that the $TOMCAT_ACCOUNT part is okay....
0
votes
1answer
35 views

Using qgrep and -e doesn't give what I want

I'm using a windows version of grep (qgrep) and I'm using the -e argument and I'm not getting what I want. I have a router log file that I'm trying to process and specifically I have: SRC=18.x.x.x or ...
0
votes
2answers
47 views

Search through on Linux files and filter out specific string and remove everything else

I am trying to find an efficient way of searching through a whole set of files in a directory and only looking for a specific string up to the first comma. Example of the postgres log file: Apr 27 03:...
-1
votes
3answers
57 views

Combine two pipe commands into a single command

I have theses two codes and i want to merge/combine them into a single one : rostopic echo /cmd_vel | grep -A 3 angular | grep -v x | grep -v y | cut -d : -f 2 rostopic echo /cmd_vel | grep -A 1 ...

1
2 3 4 5
89