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

learn more… | top users | synonyms

2
votes
2answers
62 views

Find out on which line in text file is matching word

Is there any way to find out on which line of the text document is some word which is matching pattern for example with grep or something. Thanks.
6
votes
4answers
561 views

Can I use Find and Grep in one line

I am a complete novice in UNIX and desperately need some help. I have a directory structure based on events. In these events I have one type of file which does or does not contain a pattern for ...
1
vote
2answers
111 views

Search only in plain text files that are not source code

I use following command to search for string ELF in plain text files under the current directory recursively: grep ELF -r . but it also searches in binary files (e.g. zip file, PDF file), and in ...
1
vote
6answers
111 views

filter out length

I have a file which contains 3940 sequences and looks like >TCONS_00000066 gene=XLOC_000030 CCGCCGGCTGCTGCGCGCACCGACTTGTCACCACCCCAGCACGTCCTCCACGTATACAAG ...
1
vote
2answers
85 views

Why is grep searching more than the files I want with asterisk?

Deep within a bash script I have grep -Ech 'string1|string2' /server/directory/$servername_log_20150312* | awk ... I was getting the "too many arguments" error so I turned on set -x and I see that ...
1
vote
2answers
278 views

How to put $@ in quotes?

My bash script looks like this: #!/bin/bash grep -r --color=always $@ . | nolong The file is saved in /usr/bin/findstr Everything's ok when I run this: findstr hello But when I run this: ...
0
votes
1answer
31 views

Find a file that doesn't include specific characters

I want to find a specific file that doesn't start with a,k,G or Q and in which the third letter in the name is not a digit. I have tried many links, but found nothing regarding to this composite ...
-2
votes
2answers
37 views

grep to get all the getters from a java file

I have a java file called Friends.java . There are 5 variables and each variable has its own getter. Assume that all the functions below follow standard java standard, i.e public methodName(){ //Some ...
0
votes
0answers
19 views

Grep not writing output until end of input [duplicate]

I have some script that is taking a long time, and producing a lot of output. I want to send the full output to one file, and pick out some specific lines to be directed to another file. Since it ...
2
votes
3answers
168 views

Keep a tally from a log file

I have a file called output.log which has this content: Thread started Thread finished Thread started Thread finished Thread started Thread started I monitor its output using: tail -f output.log ...
4
votes
3answers
310 views

Output to be saved in file named same as the input file [duplicate]

I have one input file and run some command but want the output to be saved with the same name as the input file has. I tried below command but it makes the output file blank: cat file1 | grep ...
1
vote
2answers
55 views

How would I grep for a password file entry without using 'username'

Can a who command be integrated to find the current logged in users password file entry?
4
votes
1answer
38 views

ack.pl tool and ack.pl flags

I am using the ack.pl tool in order to search string or IP’s in files The official site of ack.pl is - http://beyondgrep.com/documentation/ Example of ack.pl CLI ( want to find the string ...
4
votes
2answers
112 views

Regular expression to match sequences of alphanumerics

Any way using grep/awk/perl to match lines in the form *.* = *.* (i.e. ac4df.bx5dfd8g = ce5def.dd5f7gdgf ) Where * means 0+ alphanumeric char?
0
votes
0answers
61 views

SED: print entire paragraph for specific pattern while loop

I find partial answer about my problem on this question but i still have trouble. I need to use a variable as a pattern for the sed command in a loop sed -e '/./{H;$!d;}' -e 'x;/'$var'/!d;' The ...
0
votes
1answer
49 views

grep recursively in ksh on AIX [duplicate]

How do I grep recursively in directories and sub directories in ksh on AIX? I have tried grep -r but this is not available.
0
votes
2answers
50 views

Not getting grep with a variable

I am assigning a variable to echo command which generates a random number. For eg: n=$(echo $(( (RANDOM%6) +1)). I have to grep this variable in /etc/passwd. So, my syntax reads like: n=$(echo $(( ...
0
votes
2answers
38 views

Filter hyperlinks from web page and download all that match a certain pattern

I wanted to download all graphic files from our organisation's graphics repository web page. They are Illustrator (.ai) format and Corel Draw (.cdr) format. They are directly hyperlinked (i.e. <a ...
1
vote
1answer
50 views

Searching file for string surrounded by two other known string?

Question title may be kinda vague, but heres what im attempting to do. I have a html file locally on my server which is changing fairly regularly. It has multiple occurrences of: <p>Jumble of ...
1
vote
1answer
56 views

How to use grep/awk/unix to match all lines from one file in another file, even if they are duplicates

I'm trying to retrieve the the matching lines from a file, however the file that has the "index" or list of matches to retrieve also has duplicate entries and I want to print out the duplicates as ...
0
votes
2answers
85 views

Grep for a word within two inverted commas

How to grep for a word within two inverted commas. The word may contain any number of characters . e.g "two" , "three"
2
votes
2answers
127 views

How to grep twice?

[user@notebook ~]$ printf 'adgaa alpha lajsd assa ><>4 saf\n63SXYZae fkrk safXYZek\nsaf betf!%saa sDGFXYZFalf\n' adgaa alpha lajsd assa ><>4 saf 63SXYZae fkrk safXYZek saf betf!aa ...
1
vote
1answer
73 views

Find all the modified svn files and copy files modified in the same folder structure

I get all the modified svn files using svn st | grep ^M command M student/includes/class_student_promotion.php M student/includes/class_student_report.php M ...
1
vote
1answer
16 views

Searching for terms that occur exactly once in a set of files

Similar to this question: Searching for terms in a set of files, only I expect each term to occur at least once in the set of files. How can I modify the search so that I can get a subset of the list ...
0
votes
3answers
58 views

grep randomly appearing and disappearing in ps aux (ps aux | grep python) [duplicate]

This isn't an actual problem - but more of a curious question, when I run while true; do ps aux | grep abc; echo done; done I get the following: user 29733 0.0 0.0 11748 924 pts/1 R+ ...
0
votes
2answers
69 views

Is `grep -P` (Perl/Python regex) portable on most linux distributions

I prefer (Perl/Python Compatible Regular Expressions) regular expressions. man grep: ...., but only work if pcre is available in the system Is this supported on the most common linux ...
2
votes
4answers
39 views

grep and print how many times my pattern in file 1 is present in file2

I have a file1 (list of my pattern) like this: file1 Fatty_acid_degradation Aminobenzoate_degradation Amino_sugar_and_nucleotide_sugar_metabolism Amoebiasis and I have a file2 (list of all the ...
1
vote
1answer
163 views

remove lines where a field's value is less than or equal to 3 - sed or awk?

I need to remove every line that has a value of 2 or less in the 8th field (column). My data looks like this: 12-31 Airport 189 379 41 49.70946503 -124.91377258 2 2880 30.8 01-01 ...
6
votes
6answers
2k views

How do I grep recursively through .gz files?

I am using a script to regularly download my gmail messages that compresses the raw .eml into .gz files. The script creates a folder for each day, and then compresses every message into its own file. ...
2
votes
4answers
104 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
46 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
103 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
509 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
42 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
57 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
313 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
2answers
69 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
268 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
35 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
80 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
60 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
923 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
72 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
316 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
64 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 ...
4
votes
2answers
79 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: ...
1
vote
1answer
57 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
81 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
200 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
50 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 ...