grep is a command-line tool for searching text patterns in files

learn more… | top users | synonyms

0
votes
4answers
75 views

Why isnt this simple grep/sed script working [closed]

I have a variable with, among others, a line that looks like this iBMC=277 I'm trying to match that like this: BMC="$(echo "$allnow" | grep iBMC=[0-9] | sed 's/iBMC=//g')" This makes BMC empty. ...
1
vote
1answer
30 views

How do I get grep to search for ebuilds with specific strings and produce an output containing only the ebuild's location?

I have been trying to create a Bash script function that can be used to search for and open ebuilds with desired strings in Atom (the text editor). This is my current Bash script function (stored in ~/...
2
votes
3answers
76 views

How to extract particular field from rows from a file, based on matching subsequent rows

I am trying to replicate a workplace problem. I have a xml file like below [~]$ less -N sample.xml 1 <SOURCE BUSINESSNAME ="" NAME ="TABLE1" FOO="ABCD"..... > 2 <SOURCEFIELD ...
14
votes
1answer
761 views

How to “grep” for line length *not* in a given range?

NOTE: This question is the complement of this Q&A: How to "grep" for line length in a given range? How can we grep for lines that have less than 8 or more than 63 characters, none ...
1
vote
1answer
75 views

How do I grep two patterns from one file and direct the lines to different output files depending on which patter matches?

I'm searching for two patterns from very large files and I don't want to grep more than once. I'm currently running this command to look for the patter, then if found also take the one line before ...
3
votes
2answers
64 views

How to use grep to return lines with an hexadecimal number in a given range?

If I have, say: blah;PC=1234abcd PC=4444bbcd;blah PC=0000abcd;;foo PC=1234abff How do I grep for lines with PC values in a given range, say 1234ab00 to 1234b0ff. The - range option seems to only ...
5
votes
2answers
2k views

Find files containing string in file name and different string within file?

I would like to (recursively) find all files with "ABC" in their file name, which also contain "XYZ" in the file. I tried: find . -name "*ABC*" | grep -R 'XYZ' but its not giving the correct output....
2
votes
2answers
49 views

How to view all ancestor processes?

How can I view all the ancestors for all instances of a given process name?
3
votes
1answer
78 views

grep two conditions, one negated, without a pipeline?

Assume we have the following test.txt: # commented line, no match # commented line, would match /app/ # again commented, would match app non commented line, matchin /app non commented line, no match ...
3
votes
3answers
88 views

Print all matching lines and the previous unindented line

For example, lets say I want to find all lines with 'matching' and the previous unindented lines in this text. Container 1 some text some text matching text some text Container 2 some ...
7
votes
5answers
1k views

How to find lines containing more than 100 characters and contains “if”?

So, probably I should use grep for this. As long as I need recursive search I should use grep -r. But then I don't know what should I do next ;) How can I do that?
1
vote
2answers
60 views

Use of \$ at end of variable name passed to grep

I was going through one of the shell scripts and found a line: ls $dir | grep -c "$NAME.${var}\$" I understand that $ would expand the variables NAME and var, but is it required to put \$ at the ...
0
votes
1answer
28 views

what grep -oh “[*?<com]” do?

I am trying to achieve something and in the experiment I came through following case , could somebody explain me how to understand whats happening. echo " Agent process not running on www.raja....
0
votes
2answers
52 views

how to parse hostname from a line

I have a line : Check space in www.raja.server.local.com and it is 40% full in /usr I want to just parse www.raja.server.local.com from above line. Note: www.raja.server.local.com can be any ...
0
votes
0answers
198 views

How do I use grep to search for strings that exist both on single lines and multiple lines?

I am searching large amounts of SQL scripts for data dependencies but due to variations in the scripts, I have encountered an interesting problem. If I am searching for the word FROM it only returns ...
2
votes
1answer
186 views

GREP exclude first 11 values

I have a massive log file that I need to filter. In this log, I want to display all logs that contain the string dns and I want see them just once. i.e from this: Dec 9 07:24:02 94.15.218.140 ...
0
votes
1answer
78 views

How to Count the Number of Lines of an Output?

Let say I have the program: Calculate.py Is there a unix command-line that counts the number of lines outputted from my program, Calculate.py?
0
votes
2answers
389 views

Search for a specific word in each line and print rest of the line

I have text file with server URL lines like: request get https://abc.net/search?q=hello/world/hello/word/search=5&size=10 request get https://abc.net/search?q=hello/world/hello/world/hello/word=5 ...
1
vote
2answers
109 views

use find and grep to find lines that contain some string and don't contain other string from files

First, I try the following code find . -name "*.cfg" | xargs grep "good"|grep -v "^\#" In the current folder, I get the list with the file name's extension is "cfg". Then I want to search the ...
10
votes
6answers
6k views

How do I pipe ls to grep, and delete the files filtered by grep?

I wanted to delete some package in my home file, but the filename was too long (google-chrome-stable_current_i386.deb). So, I decided to use the command ls|grep chrome|rm to pipe the files to grep to ...
1
vote
1answer
56 views

Grep exact numeric match

I am using grep to extract some exact numbers in column #2 of a long file. I am using the following code: grep -e "^71161 |^71072 |^72617 " mainfile > outputfile This does nothing in ...
0
votes
1answer
40 views

Matching in sequential order

I have to match multiple strings in a file using grep command, following is the command i am using: grep -e 'str1' -e 'str2' file.log I need all the lines containing str1 and str2 but in the same ...
0
votes
2answers
25 views

using egrep & regex

Suppose I have the following text file called inputFile: hello HELLO Hello World wOrld asdgfsafd abc 123 1 3 5 a b and I want to print out the lines containing only one word(any sequence with ...
8
votes
5answers
755 views

Find last occurence of string in multiple files

I need to search multiple log files (all files generated in last 24 hours, all kept in same directory) to find the last occurrence of a string. This is the command I wrote: find . -mtime 1 | grep ...
4
votes
1answer
144 views

If empty condition behaviour

What is the difference between: if echo " T " | grep -q " F "; then echo FOUND; else echo NOT; fi And: if ""; then echo FOUND; else echo NOT; fi The output of first command is: NOT The output ...
0
votes
2answers
56 views

Conditional grepping

I have a scenario to handle. Need help with that... I have a config file and its content looks something like below: Jobname|Type|Silo|Description #comment1 #comment2 job1|me|silo1|...
1
vote
1answer
55 views

Find value for a given key using grep in the string

How can I grep SSID value from the string below using grep? SSID: Home, BSSID: aa:bb:cc:dd:ee:ff I tried grep -oh "SSID:.*," and other combinations but to no avail. The reluctant ? quantifer ...
3
votes
2answers
98 views

Search in specific column for pattern and output entire line

I'm working in HDFS and am trying to get the entire line where the 4th column starts with the number 5: 100|20151010|K|5001 695|20151010|K|1010 309|20151010|R|5005 410|20151010|K|5001 107|20151010|K|...
1
vote
0answers
94 views

Extract coordinates of matching text in PDF

Basically I want to grep a string in a PDF and get the coordinates of the matching result(s). I already use pdftotext to do the opposite, namely to extract some text given its coordinates. In ...
4
votes
5answers
277 views

Print several lines after nth occurence in bash

I'm looking for a way to search for the nth occurrence of a pattern and print k lines after the pattern. I guess awk would work better than grep in this case but I cannot figure out the way to do it ...
0
votes
5answers
231 views

How to use grep to extract file names at end of lines?

I have a log file which contains information such as output using ls *.CCD from directory /var/tmp/Person: -rwxr-xr-x 1 bv90 dkas 153698 Nov 18 13:08 WE994002.CCD I have many such ...
2
votes
3answers
47 views

how to extract a number from the line in unix

I need to find the first occurrence of the attribute ICount and its value must be returned. Only the number from the attribute. How to get it? < FCount = "1" ICount = "0" Ccount= "1"> Please ...
2
votes
1answer
103 views

Grepping and sedding IP from ip addr show

I'm trying to get just the local IP of my Arch VM. I've managed to get just the line containing what I want with grep, but I also want to trim it down with sed. inet <<192.168.0.16>>/24 ...
1
vote
1answer
45 views

Validate a list of xml files

I'd like to validate a list of xml files against a schema, and only be notified of failures. This command seems to work, but the last grep command has no effect: find -iname "*.xml" | xargs xmllint -...
0
votes
2answers
46 views

Find the number of all typed commands which include a string , using grep

I'm searching through my bash history log for all the typed (started) commands which included the string x. For some reason, the homework checker always says that the number I'm giving is bigger than ...
1
vote
2answers
69 views

Grep from a line to a line [duplicate]

I have a file with hounded of thousands lines. I need to grep from a line to another line and include everything between these lines i.e lines from Wed Nov 25 23:08:01 GMT 2015 to Wed Nov 25 23:59:...
1
vote
5answers
218 views

List (or move) only files with a certain number of lines?

Dealing with a whole bunch of two-line config files, I'd like a way to exclude any files that have a different number of lines. So, something like: mv * destdir only if file contains exactly two ...
0
votes
4answers
187 views

How to display output of command while also parsing it?

I have two commands, build and deploy. Currently I run build manually, parse its output using my own eyes, and use a value I find in the output as an argument to deploy. The process looks something ...
1
vote
2answers
52 views

how to grep for packages on basis of uncompressed file-size?

In Debian when you look at a package, you get lot of info. Including the uncompressed file size of the package. Is there a way to grep through the file-listing so that packages appear either from ...
1
vote
1answer
56 views

What does a backslash represent when searching for decimals

I want to understand what the backslash represents in this command. grep "\.900983" table I know what the command does, it searches for the 900983 value in table, I'm just not sure of the purpose of ...
0
votes
4answers
90 views

How to grep the result of a grep?

I need to grep some files to see which ones contain a certain word: grep -l word * Next I need to grep that list of files to see which ones contain a different word. The easy way would probably be ...
0
votes
2answers
33 views

finding how many options ls have

Just for practise i want to find out how many options does ls command have. I have written following piece of code man ls | grep -o -i '\-[a-z0-9]$' Why does this piece of code only printed -C and ...
1
vote
1answer
248 views

Find and delete lines containing multiple patterns in a file

I have a list of strings and want to find and delete lines containing these strings in a file. A short example of the list of strings is listed as below. File S 1Mo 32,33 2Mo 7,26 2Mo 7,27 2Mo 7,28 ...
-5
votes
2answers
85 views

Search word structure using grep

Some English words contain an "abba" structure, such as "tomorrow" or "better". How many lines of a given file contain such a word? How do i search such words using grep?
-2
votes
1answer
184 views

Find vowels using grep command

How do i find three vowels in a row in a given file(not counting Roman numerals as words, and not counting "Y" as a vowel)?
0
votes
0answers
48 views

Finding word with centain length containing characters from interval

I am trying to print all words that are 3 chararcers long and those characters are from [a-s] interval. I have tried following grep '\<[a-s]\{3\}\>' file.txt which outputs nothing , i have ...
1
vote
1answer
47 views

usage of apostrofe in grep rexExp

I have recently started learning regExp and found nice example of it in shell using grep to extract only anchor tags url e.g <a href="unix.stackexchange.com"></a> grep - 'href="[^"]*"' *....
0
votes
1answer
225 views

Passing a variable argument to egrep in a bash script

I have a script, myScript, which is trying to egrep the script argument in a file. Somehow variable expansion isn't working properly with the egrep command. I believe I've isolated the problem ...
0
votes
1answer
36 views

How to recover a node/content from a tarfile that's been overwritten

Disclaimer: I'm not very good at writing questions, and mine is a very specific scenario. So I'm just going to jump straight into the situation: I was browsing my filesystem, and somehow managed to ...
3
votes
1answer
37 views

grep search for any number in a range

So I have a file with a number of records that look like the following: Peugeot:206:2000:Red:1 And I'm trying to grep search for any that contain a year 1995-1999. I have tried grep '[1995-1999]' ...