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

learn more… | top users | synonyms

2
votes
1answer
16 views

Extracting 1st word after matching when matched word has []

I have an issue when I try to extract the 1st word after grep matches my pattern . Let me show you an example : cat test.txt [profile dev] xxx xxx [profile prod] xxx xxx now I want to extract the ...
0
votes
3answers
27 views

Is there a way to grep a folder and show all lines containing non-ascii characters?

Some code I am working with has a bunch of comments written in Japanese and I am working on translating them to English. Is there some way to "grep" for all lines containing Japanese characters or at ...
3
votes
5answers
181 views

How to grep the n-th substring between given delimiters?

Let's say we have a string and its delimiter is ?: Leslie Cheung April 1 ? Elvis August 16 ? Leonard Nimoy February 27 I know how to grep the first substring between delimiters: echo $above_string ...
2
votes
1answer
264 views

grep behaving abnormally

grep is behaving different when letter a is being searched. when letter a is included in search criteria, it is not searching for any other letter. But it is not the same case with other characters. ...
2
votes
2answers
36 views

grep with count of individual patterns

I have a file with MAC addresses (1/line with : as separator, sorted) and I need to find out how many times each of these MAC addresses appears in the file. I modified this: How to count occurrences ...
0
votes
3answers
33 views

grep log lines of a specific id request

So, I have the following log sample: 2015-03-30 10:19:44,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 1 2015-03-30 ...
0
votes
2answers
51 views

How to print an element from the corresponding immediate next column after searching the element in the current column?

I have thousands of lines as seen in the following list. file name = "textfile" 3 2 3 1 4 7 5 8 6 8 9 8 8 9 4 7 3 9 2 3 4 4 9 2 2 2 0 9 4 0 0 9 8 2 4 0 I have to search a particular element – ...
1
vote
2answers
42 views

Parsing C Style Multiline Comment

I want to filter non-commented javascript with sed and output the line number Here is the example: /*! * jQuery UI 1.8.17 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual ...
2
votes
3answers
102 views

How can I extract the text between two strings in a log file?

I think I have a very similar question to this one but I see it was closed due to being unclear so I'll create a new question. I've got a log file that contains one-line entries with multiple ...
-1
votes
1answer
38 views

Is it possible to get static backreference with grep?

I try to match a a group twice in multiline. grep -Pz 'Source: (?<group>.*/).*\n.*\n.*\n.*\k<group>|$' it work except one major problem - it doesn't, \k<group> search for .*/ and ...
2
votes
3answers
129 views

find and grep pipeline returning nothing

I have files named lect1.txt, lect2.doc, and lect3.doc. I want to get a file which is a .txt file, and contains lect as the filename. I tried find *.txt | grep lect* and it returned nothing. ...
18
votes
2answers
1k views

Why is “grep keyword” causing the terminal to stand by forever?

When I type "grep doc" in the terminal, it just don't do anything, stopping the terminal from doing anything else before I escape using Ctrl+C or Z. I know this isn't how I'm supposed to use grep, ...
0
votes
1answer
49 views

can we get sorted grep output

I have same: 1.txt with apple written in it, 2.txt with mango written in it, 3.txt with apple written in it, 4.txt with mango written in it. grep -e apple -e mango *.txt will give result as: 1.txt: ...
0
votes
1answer
41 views

Search a file for a string in multiple directories

Can someone please help me with a command to search a file for a string in multiple directories? I am searching for the VIP in httpd.conf in multiple httpd instances. I am using: find ./ -name ...
0
votes
1answer
40 views

What's a way to get the first network interface using grep in ifconfig? [closed]

Just trying to figure this out for a System Administration introduction course, and I can't seem to get it.
0
votes
1answer
27 views

Using regular expressions to search a word list. Finding 2 letter words instead of 3. Why?

I am studying regular expressions and I am stumped. Here is my process so far.... I downloaded this file. wget http://www.mieliestronk.com/corncob_lowercase.txt mv corncob_lowercase.txt words.txt ...
0
votes
6answers
49 views

How can I use grep to search only on the first line of files for a specific string?

How can I use grep to find a string in files, but only search in the first line of these files?
0
votes
1answer
22 views

Cron start script twice

I have a backup script which sends my snapshots to a off-site location. 0 0 * * * /root/backup/backup_incremental >> /root/backup/test.log For some reason my PID file which should stop the ...
1
vote
1answer
29 views

Grep rows where change occurs in columns

I'm wondering if there is a grep command to return the row lines where a character in a column changes... for example if I have a file: 1 1010 1 101010 1 10101010 2 1010 2 101010 2 10101010 And I ...
2
votes
4answers
115 views

How do I perform xargs grep on grep output that has spaces?

I'm searching for files based on a regular expression, and then I'm trying to search those files for content. So, for example, I have something like #Find all C++ files that match a certain pattern ...
0
votes
2answers
49 views

grep with variable

I am trying to create a script to monitor all logins using sudo, both success and failure. Right now, I have: set tdate = $(date "+%b %d") set attempted_su_log = /var/log/suattempts cat ...
4
votes
4answers
134 views

Insert new lines with missing values (NA)

I would like to insert new lines in text files if there are missing values. I have for example the following text file (A.txt), for which line 5 is missing. In addition, as the file should have 12 ...
1
vote
4answers
67 views

How to search the word after the specific line in the file in linux?

I have a file with 100 lines and i have to search the word happy but the search must start after the 50th line of the file. what's the exact grep command is used in linux?
2
votes
2answers
45 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
500 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
75 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
89 views

filter out length

I have a file which contains 3940 sequences and looks like >TCONS_00000066 gene=XLOC_000030 CCGCCGGCTGCTGCGCGCACCGACTTGTCACCACCCCAGCACGTCCTCCACGTATACAAG ...
1
vote
2answers
69 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
275 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
26 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
32 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
163 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 ...
3
votes
3answers
248 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
27 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
33 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
111 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
43 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
22 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
48 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
23 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
45 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
41 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
61 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
83 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
36 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
14 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
37 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
47 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
30 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 ...