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

learn more… | top users | synonyms

0
votes
0answers
7 views

grep. Find multiple AND patterns in any order using single condition

Is there any way to use grep to search for entry matching multiple patterns in any order using single condidion? As showed in How to run grep with multiple AND patterns? for multiple patterns i can ...
0
votes
1answer
31 views

Colorize line number in grep

Is there a way to colorize line numbers when using grep with the -n option? For example, echo "hello" | grep -n lo outputs 1:hello where lo is colorized in red (being the match). Can I configure ...
0
votes
3answers
76 views

Using grep in shell script

I have a text file which looks like this(I am showing few lines of it) INDEX : 1 snRNA_seq:TTTTGGAGCAGGGAGATGGAAT miRNA_seq:CTCCTGACTCCAGGTCCTGTGT target: ...
1
vote
3answers
153 views

Grep all string which do not starts with number(s)

I'm looking for grep to show all characters which do not starts with numbers. I have done something like this: grep -v '^[1-2]*[a-zA-Z]?' -o but it do not work. Do you have any idea for some reg ...
0
votes
1answer
36 views

What is the meaning of (^| )ABC( |$) as an extended REGEX ?

I came here across the command grep -E '(^| )ABC( |$)' file1 I am confused how to interpret the regular expression therein, because I know the ^ and $ character as beginning and end signifier, but in ...
0
votes
2answers
30 views

A batch that cout the number of occurrences

I've to extract the number of words using each letter of the alphabet from A to Z. The script that i've to create create take as parameter the name of the dictionary file to analyze and will be used ...
2
votes
1answer
190 views

How to grep exact word with only space as word separator

For Example: I have file like following: AA ABC-AA-AA AAA ABC-AA ABC.AA ABC AA ABC.A AA If I use grep -w "ABC" file1, I am getting all the lines. But I should only get 3rd line: ABC.AA ABC It is ...
0
votes
0answers
11 views

Nmap and grepping [closed]

i would like to do reverse dns resolution using nmap where the output will be like below http://www.blackbytes.info/wp-content/uploads/2013/07/nmapSL1.jpg how do i go about it using grep, thanks
0
votes
2answers
42 views

Match lines not ending with an specific character

I have been learning linux commands and got this error. My text is here: Fred apples 20 Susy oranges 12 Mark watermellons 12 Robert pears 4 Terry oranges 9 Lisa peaches 7 Egemen aaaa 12 Susy oranges ...
3
votes
4answers
216 views

Grep pattern inluding dashes and restricting to a filename extension

I am trying to use grep to find some tex files containing the pattern ->-: grep -R -- "->-" *.tex But this doesn't work. If I do: grep -R -- "->-" instead, it works, but is really slow ...
-2
votes
1answer
27 views

Using 'grep' to search for a specific pattern [duplicate]

I'm playing with the Linux terminal and I have to do a exercise which states that I have to find inside a file for any line that contains at least an a, b and c, it doesn't matter it the lane has 2 a, ...
0
votes
3answers
60 views

Using The Grep Command

I have two simple questions regarding the use of the grep command that I'm sure that someone can help me with. What I want to do is: show the total lines (processes) running as me except for the ...
0
votes
1answer
39 views

How to find with grep lines that end in a certain string?

I know that to find a REGEX that ends in a certain string I have to write "string$". Although I tried the following variations of grep : cat foo | grep "string$", cat foo | egrep "string$", grep -E ...
4
votes
3answers
374 views

Why is this command not working: “ps aux | grep xscreensaver”

I didn't see any hits about this on google, so I'm asking you: I just tried to run this command in an ssh session, local is Debian Wheezy KDE, remote is Fedora 21 Gnome: ps aux | grep xscreensaver ...
0
votes
2answers
55 views

What regular expression in grep searches for strings of three same letters in a row?

I have a text file and I am using the grep command with a regular expression to get only the lines which contain three same successive letters, e.g.: aaa bbb ccc ddd What regular expression do I ...
6
votes
3answers
289 views

How do I use the regular pattern operator {m,n} in grep?

I have a text file, from which I need to select only those lines, which include the string "tt". So I tried this on the command line: grep "t{2}" textfile Allthough I know the textfile contains ...
0
votes
2answers
23 views

how do I find the location of mysql drivers on CentOS 7?

MariaDB is installed on a remote CentOS 7 server. How can I find the location of the nearest equivalent to mysql-connector-java-5.0.8.jar in the server's file system? grep seems to only search ...
3
votes
2answers
42 views

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

I need to get only the lines from a textfile (a wordlist, separated with newline) that has a length range of minimum or equal than 3 characters, but not longer or equal then 10. Example: INPUT: ...
0
votes
1answer
35 views

Only grep for lines that only contain alphabetical characters

Question: How can I grep for lines that ONLY have the following characters (all in lowercase)? aábcdeéfghiíjklmnoóöőpqrstuúüűvwxyz example: INPUT: árvíztűrő tükörfúrógép árvíztűrő ...
3
votes
3answers
40 views

Run fgrep multicore mac os x

I'm running this command on my Mac OS X on 8 cores: for i in $(cat file1);do grep "$i" file2; done > output.txt My file2 is 9 million lines so it takes a lot of time. Is it possible to use all ...
3
votes
6answers
147 views

How to grep a line with unknown number of its indented lines

I often need to grep a line with its indented sections. For example, if the indented line number may be known, we would achieve this goal with the following: $ lspci -vq | grep -i wireless -B 1 -A 5 ...
0
votes
1answer
31 views

Regex for matchng anything between parenthesis

I have the following regex so far: printf "this is (test.com)\n" | grep -Po '(?<=\().*(?=\))' The above regex will print the desired output, which is test.com As far as I am adding new ...
0
votes
2answers
28 views

How to match multiple lines starting with a TAB, and the line before the 1st one in a group?

I've got some third party log files I'm trying to pull errors out of on the command line. The logs look like this: time=1 time=2 time=3 at com.test.com.... at com.test.com.... at ...
0
votes
1answer
21 views

grep --exclude-dir behaviour: a bug or a feature?

I have noticed an annoying change in grep -r --exclude-dir behaviour. Consider the following test: mkdir -p ./d1/d2 echo 'randomtext' > ./d1/d2/testfile grep -nr --exclude-dir ./d1/d2 ...
0
votes
3answers
48 views

How can I output sample rows from a .csv?

I'm doing a lot of data merge printing and would like to be able to output, say, 10 samples from a large database. My goal would be to extract the 10 rows spread evenly from the supplied .csv ...
0
votes
2answers
41 views

How to add a column if line contains string?

If I have a tab-delimited file containing the following lines: Sample1-Baboon 1 2 3 4 Sample2-Human 1 2 3 4 Sample3-Human 1 2 3 4 Sample4-Baboon 1 2 3 4 How can I add a new column ...
0
votes
1answer
60 views

Reading a string till a key word and replacing from there with another string

I am new to UNIX and am practising shell scripting. I have an application where I need string searching and replacement. There are some lines in a file 1 and file 2. I have a search key word. If the ...
1
vote
1answer
101 views

grep (/sed/awk) month range

I've looked around for solutions to this, but it's sort of difficult to search for the solution to such a specific problem (lot of words to put in Google). So, I have a file with data that looks like ...
-1
votes
1answer
36 views

Script to `grep` a file with variable [duplicate]

while read wholeline do echo ${wholeline} --outputs John Jones #grab all the lines that begin with these values #grep '^John Jones' workfile2 --works, prints contents of workfile2 where the ...
1
vote
2answers
55 views

Multiple grep commands with sort

I have a text file containing a list of student grades: Andrew cooking A Andrew cooking B Andrew computing F Steven java C Steven python E Ben C++ D Ben python C Jamie java E Jamie C++ E Jamie C++ B ...
4
votes
2answers
80 views

Characters visible in vi, but not in cat.

I have a 300 lines file with ^@ character between each characters in the file. (I cannot post the entire contents for security reasons, so I am pasting only the first line) [mercury@app01 ftp_logs]$ ...
1
vote
1answer
40 views

Find which file contain a particular keyword using `grep`

Suppose I know I have to change myhostname = abc.domain.lcl to myhostname = abc.domain.glbl directive but I don't know in which file exactly the directive myhostname is in (i.e., say I have never ...
7
votes
8answers
586 views

Using 'grep' to find lines that contain all of three specified characters in any order [duplicate]

We have a document which contains lines and we have to find if [a|b|c] appears at least once in every line no matter which order. For example: Input: abc bca cab hhfdhdhfabjfdjdjff acjfdjdfjdf ...
0
votes
2answers
21 views

How to select specific sets or sturture from a file, if struture contains specific string?

I want to extract the sets with having specific string, for example: file abc.txt contains abc 123 abcd 1234 abcde 12345 abc 123 abcd 123 abcde 12345 abc 123 abcd 1234 abcde 12345 Now from the ...
3
votes
2answers
63 views

Grep command that finds/excludes all line where a separator character appears a certain number of times?

Is there a Unix utility to restrict a file or directory listing to given minimum and maximum number of levels deep? I have a git command which displays a unique listing of the directories where files ...
-1
votes
1answer
36 views

How can I recursively grep through several directories at once?

I use grep -r all the time to find occurrences of a string within files in a given directory: $ grep -r "string" app/assets/javascripts > app/assets/javascripts/my_file.js: this line contains my ...
3
votes
2answers
140 views

Capture in shell variables the arguments after a command (between brackets)

Suppose I have a file that contains, among many other things, \command{arg1,arg2,arg3} (arguments been paths, expressed with /, ., characters and numbers) But that a user can as well call it ...
0
votes
1answer
26 views

is there a way to see a listing of packages ONLY from Debian-experimental?

I am on Debian testing/Jessie and I have debian-experimental as well as in my /etc/apt/sources.list. So I am looking to list packages in two ways :- a. List all the packages which are in ...
1
vote
2answers
35 views

Why does regex with \\$\{ work with egrep, but not with sed?

Given a text like this ./RFF_09 -f${FILE} -c${COND} inside a file, this egrep command will correctly match: egrep './RFF(.*) (.*)-c\\$\{COND\}' file but this sed command will not sed -n ...
1
vote
1answer
29 views

Problem with grep on multiple files and not getting desired output

I am using the below command on a file to extract few lines based on chr# ( different chromosome numbers). This is just a single file am working on. i have 8 such files and for each file I have to do ...
1
vote
5answers
374 views

How to use grep and cut in script to obtain website URLs from an HTML file

I am trying to use grep and cut to extract URLs from an HTML file. The links look like: <a href="http://examplewebsite.com/"> Other websites have .net, .gov, but I assume I could make the cut ...
1
vote
4answers
223 views

Regex pattern search for alternating character case

How would I pipe the ls through grep to have an alternating character case, as output? For example: I have files (1) aAbBaBbA, (2) bAbBaA, (3) bbAb,(4) AAaBbAa,(5) BBBaaa, and (6) aBaB. I want to ...
1
vote
2answers
190 views

Why does “grep '.*[s]' file” work and “grep .*[s] file” doesn't?

Comparing grep '.*[s]' file with grep .*[s] file Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.
2
votes
2answers
69 views

How to return 0 if a pattern is matched from a file? [duplicate]

I have a binary that repacks android kernel (not mkbootimg). I'm making a script to automate the process. I don't want any output on the screen. So I have redirected the output to a file named ...
-1
votes
1answer
67 views

grep and print all pattern in one lane

I have a file with a list of pattern like this K00001 K00003 K00005 I want to grep and print my pattern in a tab delimited table (the original table is without blank line) like this: K00001 ...
3
votes
4answers
83 views

fgrep beginning of line?

I'd like to use fgrep to handle searching literal words with periods and other meta-characters in grep, but I need to ensure the word is at the beginning of the line. For example, fgrep 'miss.' will ...
0
votes
1answer
99 views

How do I grep on a live log (stdout)?

I'm not sure if that what stdout is, but that's what I think. What I want to do is filter out a certain log message when running an executable. I tried this: Executable 2>&1 /dev/null | ...
2
votes
3answers
107 views

How can I insert the contents of a file into a string in bash

I would like to append the contents of a multi-line text file after a particular line in a string. For example, if the file file.txt contains line 1 line 2 I'd like do so something like printf ...
1
vote
1answer
125 views

How to do a netstat that will only filter based on pid

How can I have the following command below just show/filter based on the PID's I'm looking for? sudo netstat -lp --inet The results come back as this Proto Recv-Q Send-Q Local Address ...
3
votes
1answer
52 views

Show exact number of CRLF occurrences in file

grep -c $'\r\n' file returns the exact same number as grep -c $'\n' file, it shows the number of LF in the file instead of the number of CRLF. (The file definitely does not contain that number of ...