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

learn more… | top users | synonyms

0
votes
2answers
46 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
40 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
168 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 ...
1
vote
1answer
50 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
72 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
79 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 ...
8
votes
6answers
2k 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
48 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 ...
1
vote
1answer
31 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 ...
1
vote
2answers
18 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 ...
9
votes
5answers
375 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
130 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
48 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 ...
2
votes
1answer
29 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
33 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 ...
1
vote
0answers
35 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
198 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 ...
1
vote
5answers
115 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
43 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
38 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
30 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
43 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
61 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 ...
2
votes
5answers
145 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
168 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
48 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
52 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
79 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
32 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
0answers
109 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
62 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
87 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
37 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
37 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
79 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
26 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
29 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]' ...
1
vote
1answer
39 views

REGEX and GREP — Search string including optional and static words

I am trying to formulate a regex expression for use with grep such that I find a static word present at the beginning of each line, followed by only one word from a list of options. That is, I ...
1
vote
2answers
99 views

Using awk and grep for iftop results

I wanted to monitor my server network send and receive rate using iftop. This is what works for me: iftop -t -s 1 -n -N | grep 'Total send and receive rate: ' | awk '{print $8}' Mac address and Ips ...
1
vote
2answers
46 views

Find values in a file from another file

I know, the title is not clear. I have 2 files, in one of this I have some values and I need to find them in another file. Instead to grep for each single value, I would use the first file to do ...
0
votes
1answer
72 views

GREP - pattern match from file only returning on last pattern in the list

I have a list of about 23 million hashes in a text file, one hash per line. Call it hashes.txt I have a list of nuisance hash values (app 40) in another text file, again one hash per line. Call it ...
2
votes
1answer
40 views

How to use BRE or ERE regex to match a pattern which does not have a specific string

How to use a posix BRE or a posix ERE regex to match a line that doesn't contain 834 at any place in string? I want to find grep '!<pattern>' file which will be equal to grep -v ...
1
vote
3answers
107 views

Match lines beginning with the same pattern in two text files

I am now having two text files with some of the lines beginning with the same pattern. For example, File A 1Mo 1,1 I love you. 1Mo 1,2 I like you. Hi 23,3 I am hungry. Hi 23,4 I am foolish. File ...
0
votes
0answers
17 views

redirect all errors of my script into errors.txt [duplicate]

I need to redirect all errors into other file which called errors.txt this is my script shell : data_in=$1 fichier=$2 cd $data_in #Purge des fichiers rm -f Split/INIT_ENC.dat rm -f ...
1
vote
1answer
38 views

copying and working on OSX .app files (folders) in linux

tldr; I want to run a script over an external hard drive and tar.gz every folder that ends with .app into their own archive. That is, I don't want them all in one tar.gz file, I want to create one ...
2
votes
5answers
161 views

How can I list the names of directories that contain files matching a regex?

Given a directory X that contains several subdirectories and files, I would like to list the names of the immediate child directories of X that (directly or indirectly) contain files matching the ...
2
votes
6answers
222 views

Extracting IP address from a text and store it in a variable

I have a text file named abd shown below. 48878 128.206.6.136 34782 128.206.6.137 12817 23.234.22.106 I want to extract only IP address from the text and store it in a variable and use for other ...
1
vote
1answer
71 views

How to find all files containing a specific string recursively on a BusyBox 1.4.2?

How to find all files containing a specific string within directory and all subdirectories on a BusyBox v1.4.2? I need to find string "AA:CC:DD:00:EE:55" or "AACCDD00EE55" BusyBox v1.4.2 (2012-06-01 ...
2
votes
1answer
70 views

bash regex: asterisk gives ambiguous search results with grep

I am using a simple text file to test the * meta-character through grep. The text file is as below: 1 11 111 1111 11111 111111 d da daa daaa b bc bcc bccc Now when I search digit 1 using grep ...
1
vote
3answers
91 views

How to grep all words starting with digit?

I am wondering how to grep all words starting with digit. So far, I have made this: egrep "^[[:digit:]]" tst But it prints me just a lines starting with digit. Thanks in advance with help.