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

learn more… | top users | synonyms

1
vote
1answer
36 views

List all regular files containing (in their name, directory or their content) a specific (sub)string

Like in the title, and also I want to print the number of the line in each (text) file where the substring occurs. So far I have: find /sys | grep "filesystem" But it appears to only look at the ...
2
votes
2answers
73 views

Why am I getting “invalid max count” from grep in an alias?

So the idea is to create an alias that will search my alias's for me. I have quite a few. dude@gnarleybox:~$ grep alg .bash_aliases.sh alias alg='alias | grep ' dude@gnarleybox:~$ alias | grep alg ...
2
votes
2answers
122 views

how to grep for specific time period in a log

We work with log files that have line entries that start with a date/time format such as this: 20150408 13:29:28 <rest of text> What would I need to do in order to grep for a date range? Say ...
0
votes
1answer
33 views

Using egrep in Bash

I'm taking a UNIX course atm, and I've got a newb question. In the following code, I'm getting an error and I'm not sure why: [name@unix ~]$cat test123 123 456 789 1011 1213 [name@unix ~]$egrep ...
0
votes
0answers
19 views

Why does not changing changing LC_ALL from utf to C speed up my grep?

I wanted to try to speed up my already fast grep. I read that changing lc_all from utf to c was supposed to do this. However, it gives no speedup. What might the reasons be? How do I "debug" this? ...
0
votes
1answer
67 views

grep: Syntax error near unexpected token `('

I have this problem: I'm looking for a string inside file . Syntax is: grep -E ‘( ^ | [[:space:]] )[A-Z]{2}[[:digit:]]{2}((- | [[:space:]] )[[:alnum:]]{4}) {3} ’ (filename) When I run this ...
0
votes
1answer
37 views

What is the email matching regex in basic regex for grep?

I created a text file and put some email addresses in it. Then I used grep to find them. Indeed it worked: # pattern="^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-z]{2,}" # grep -E $pattern regexfile but only as ...
0
votes
1answer
35 views

Find all the PHP scripts with email in my postfix mail queue

How do I find all the scripts that have mail sitting in my postfix mail queue? This server is sending out spam and I've spot checked it, but I want to make sure I haven't missed any scripts that may ...
0
votes
2answers
55 views

How to run multiple AND in grep command [duplicate]

I'm trying to run multiple AND combination in grep command, I was able to run using two patterns: grep -E 'pattern1.*pattern2' filename Is it possible to use three or four patterns using the above ...
1
vote
2answers
91 views

Finding files that contain multiple strings

I am trying to find scripts that contain common malicious code, I need to match multiple strings within each file. What I am using is working but am not sure why I get the following in the output: # ...
9
votes
3answers
688 views

Strange behaviour of “ls -a | grep ^\.”

I wanted to list the content of a pwd and display only file starting with dot. I tried ls -a | grep ^\. but I cannot figure out why the output contains also the files which do not start with dot. For ...
3
votes
3answers
125 views

extract from line to line and then save to separate file

I tried my luck with grep and sed but somehow I don't manage to get it right. I have a log file which is about 8 GB in size. I need to analyze a 15 minute time period of suspicious activity. I ...
13
votes
4answers
7k views

Grep: Show all the file up to the match

grep --before-context 5 shows 5 lines before the match. I want to show everything before the match. Doing grep --before-context 99999999 would work but it is not very... professional. How to show ...
21
votes
5answers
9k views

What makes grep consider a file to be binary?

I have some database dumps from a Windows system on my box. They are text files. I'm using cygwin to grep through them. These appear to be plain text files; I open them with text editors such as ...
1
vote
1answer
83 views

string search using awk

I have file-1 which has list of transaction id . File -1 201503301616|9b8791b3-f860-409f-aad0-24debf834c1b|10.233.18.29.677220869928387637969 ...
0
votes
0answers
40 views

awk & grep to search for all strings in file1 on file2 where strings can have pipe [duplicate]

Please ignore - this post is a duplicate of this one. I have file-1 which has list of transaction id . File -1 ...
3
votes
1answer
46 views

Grep a specific word in a single string with repetitions

How can I grep a specific word in a single string that contains repetitions? For example : Apple_1 Apple_1_Test Juice_2 Juice_2_H If I use grep -Eo 'Apple_1' I get two results (because of two ...
3
votes
1answer
44 views

Extract first word after pattern that includes `[…]`

I have an issue when I try to extract the first 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 ...
1
vote
3answers
142 views

How to perform grep onto the output of ldd properly ?

# ldd /usr/bin/ffmpeg linux-vdso.so.1 => (0x00007ffffc1fe000) libavfilter.so.0 => not found libpostproc.so.51 => not found libswscale.so.0 => not found ...
1
vote
4answers
61 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 ...
1
vote
2answers
75 views

grep or find a pattern in all directories [duplicate]

I have an account number 1234-5678, I am trying to find it in all files of directories. I used the below command but no result found. grep "1234-5678" */ Please can someone help me how to find it in ...
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 ...
3
votes
5answers
300 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
279 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. ...
0
votes
3answers
44 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
59 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 – ...
2
votes
2answers
42 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 ...
1
vote
2answers
49 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
175 views

Print total free memory from `free -m`

free -m currently puts out something like this. I would like to know using grep/awk how we can get the total free amount. i.e. 9083
15
votes
8answers
9k views

pgrep and pkill alternatives on mac os x?

Are there alternatives to pgrep and pkill commands on Mac OS X or should I just create aliases for them using other commands available for me?
2
votes
3answers
137 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
42 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 ...
3
votes
4answers
7k views

Compare two text files and find matching lines

I have two files A and B. A looks like this (4 to 6 lines): GAGA CAGA GGGT TATT file B is a really big file with thousands of lines, here is a short example: AAATGTCAAGAGACAGAAATGTCAAGAGGGT ...
19
votes
2answers
2k 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, ...
2
votes
3answers
139 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. ...
0
votes
1answer
52 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: ...
2
votes
2answers
62 views

Live replacement, while viewing log using LESS

It's very convenient to monitor logs using less command - you see what is going with your system as it happening. The bad thing is that my logs are optimized for grep tool: each atomic action is ...
0
votes
1answer
47 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
6answers
58 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
33 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 ...
5
votes
2answers
3k views

tr complains of “Illegal byte sequence”

I'm brand new to UNIX and I am using Kirk McElhearn's "The Mac OS X Command Line" to teach myself some commands. I am attempting to use tr and grep so that I can search for text strings in a regular ...
0
votes
1answer
31 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
31 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 ...
13
votes
2answers
56k views

Return only the portion of a line after a matching pattern

So pulling open a file with cat and then using grep to get matching lines only gets me so far when I am working with the particular log set that I am dealing with. It need a way to match lines to a ...
2
votes
4answers
147 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 ...
7
votes
2answers
12k views

How to grep lines which does not begin with “#” or “;”?

I want to grep smb.conf and see only lines which are not commented.
0
votes
2answers
58 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 ...
8
votes
3answers
10k views

How to return both file name and line number with find … -exec grep?

When using find, how do I return the file name and the line number when searching for a string? I manage to return the file name in one command and the line numbers with another one, but I can't seem ...
1
vote
6answers
103 views

filter out length

I have a file which contains 3940 sequences and looks like >TCONS_00000066 gene=XLOC_000030 CCGCCGGCTGCTGCGCGCACCGACTTGTCACCACCCCAGCACGTCCTCCACGTATACAAG ...
6
votes
4answers
533 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 ...