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

learn more… | top users | synonyms

0
votes
3answers
35 views

What the equivalent of “grep | cut” using sed or awk?

Say I had a config file /etc/emails.conf email1 = user@dinkum.dorg email2 = user@winkum.worg email3 = user@stinkum.storg and I wanted to get email2 I could do a: grep email2 /etc/emails.conf | ...
0
votes
1answer
21 views

Filtering Log Output on Separate Lines

I did a recursive grep in a directory to find all files that would match as follows grep -ER "match_string1|match_string2" /path/to/dir/ What I get as output is: ...
0
votes
2answers
29 views

grep to ignore special characters in a file [on hold]

I have a java file and I want to list the number of times the word port occurs. But the only problem is I have many functions which have the work port in it too. Here is an example of a function : ...
1
vote
1answer
25 views

How to filter a basic csv by columns

How do I filter by third column of the following file list.txt [[ list of people ]] billy baxter - @baxter - b.baxter@woods.com james woods - @woods - j.woods@someother.com I currently have cat ...
0
votes
2answers
33 views

awk/grep to match word in two files [duplicate]

I have two files: file1: 905894 1197693 3703749 file2: 905894 Test1 1197693 Test2 3703749 Test3 I want to get the values in the second column if elements in file 1 column 1 matches any of ...
0
votes
2answers
33 views

find and list -R returning different number of files

I'm trying to create an array variable with a list of files to use in a small script, needing the full path to the file. Looking around I tried something like this: find /path/ -t f | grep ...
6
votes
3answers
114 views

Get files with a name containing a date value less than or equal to a given input date

One of my folders contains files in the following format: 3_20150412104422154033.txt 3_2015041211022775012.txt 3_20150412160410171639.txt 3_20150412160815638933.txt 3_20150413161046573097.txt ...
0
votes
1answer
37 views

Script for update

I need your help in a script used for update : OLD="int 10" NEW="int 20" i=0 DPATH="/home" for f in $DPATH do sed -i "s/$OLD/$NEW/g" $f let i++ echo "modified:" $f done what i need ...
2
votes
1answer
39 views

Execute commands from history that match regex or grep

I was wondering if its possible to execute commands from history that match a certain regex? I know you can do something like fc 232 248 And it will go into your history and then do revisions ...
1
vote
1answer
51 views

Awk Command vs Grep

I had a question regarding the awk command. I want to take a bunch of files and find a single line from each and extract them into a comma seperated text file such that I can import it into excel for ...
2
votes
2answers
152 views

Extract group name from `id` and store it in a variable

$ id usera uid=830(usera) gid=799(groupa) groups=799(groupa) I need to extract the group name from the output of id and store it in a variable. In this case it's groupname=groupa
0
votes
4answers
74 views

delete all .swp file using rm command

I am trying to find and delete all .swp files in my current directory. I was using below command: rm -i `find . | grep .swp$` But everytime it is giving me this error: rm: missing operand Try `rm ...
3
votes
1answer
99 views

Want to grep a date in a file and its next 5 lines

I want to grep the current date in a file, but also output the next 5 lines. How do i do that with the grep or anything else. grep -A 5 file.txt does not work and the output is shown below. Please ...
1
vote
2answers
35 views

How do I get a count of file references inside a folder of files with those references?

Alright, I have two folders. For simplicity's sake, I'll call them people and animals. The animals folder has a file for each animal, and the people folder has a file for each person with references ...
0
votes
1answer
43 views

Search and replacing strings in a numerical data file

I have a data file I need to edit it is in the form: ...
4
votes
1answer
73 views

How to tell “grep -w” what characters make up “words”?

$ printf 'asf .test. afd\nasaf foo-test asfdads\n' asf .test. afd asaf foo-test asfdads $ printf 'asf .test. afd\nasaf foo-test asfdads\n' | grep -w test asf .test. afd asaf foo-test asfdads ...
0
votes
0answers
13 views

How to properly structure a zgrep command to return the proper count of expression matches?

I am trying to search through several bzipped CSV files and return a count of emails that contain a .br domain extension. It seems straight forward enough but I have not been able to structure a ...
0
votes
3answers
41 views

Find the row and append to the bottom of the file

I have a big file with some record which will be having different values than others. Actual data file: 000000106500000000000129201300000U1E4600000060000+00000020400+00000002532+000000 ...
21
votes
2answers
2k views

What's the point in redirecting output of grep to /dev/null?

Consider this line: ${libdir}/bin/licenseTool check "${SERIAL}" "${VERSION}" "${PRODUCT}" ${libdir} | grep '^200' >/dev/null What's the point of looking for the pattern in the output if the ...
0
votes
1answer
30 views

match a string with special char and exact match using grep

I have a large file and want to search only specific string. eg. mobNo='xxx-xxx-xxxx' i have a lot of string in this formate. i am tring grep "mobNo=\'*\'" . can some one help me. Thanks in ...
4
votes
4answers
470 views

Grep first 50 lines of files for pattern

How might one search the first 50 lines of files in a directory for a given string? I'm specifically looking for which database table files (from mysqldump) define a specific field, but I don't want ...
6
votes
3answers
69 views

How to start multi-threaded grep in terminal?

I have a folder which has 250+ files of 2 GB each. I need to search for a string/pattern in those files and output the result in an output file. I know I can run the following command, but it is too ...
3
votes
1answer
21 views

Find repository names from gitolite info output

How do I extract the names from the gitolite info command output, for further piping into a script? I'm writing a migration script to migrate all my repositories from gitolite to a Gitlab server. ...
0
votes
1answer
34 views

Filter grep output

Using grep "val" index.php I get the list <td class=val> 7.6</td> <td class=val> 58</td> <td class=val>1013.8 </td> <td class=val> 1020 </td> <td ...
0
votes
3answers
56 views

Filtering multi-lines from a log

Should this question be moved to stackoverflow instead? I often need to read log files generated by java applications using log4j. Usually, a logged message (let's call it a log entry) spans over ...
2
votes
1answer
34 views

grep with regular expression

I want to match all the lines that are of the below pattern in a file using grep. Abc::xyz() [18-Feb-15 12:09:16] I came up with below regex with grep , but it is not returning match. Please help ...
1
vote
2answers
49 views

Why can't I pipe to ack?

So I've been trying to use grep to extract some stuff from a Mercurial log and trying to avoid using awk just to see if I can get by without it here, and failing because neither grep nor egrep support ...
1
vote
1answer
34 views

Anchors not working with grep

I am trying to do an extended grep on Android logs. However, I am not able to match the anchors for it. Here's my query - grep -A 25 -E 'show\(authenticated = ...
1
vote
1answer
75 views

Using the grep filter

I have a text file with the name "hello.txt" that contains the following two lines: Hello WORLD! Hallo world! When I wrote the following grep -i h[ae]llo hello.txt in the terminal, the output ...
2
votes
1answer
46 views

Using fixed strings in regular expressions?

I am writing a bash script which accepts a list of CSV files as arguments and outputs e-mail addresses only found in the first file. To accomplish this, for each record in the first CSV file I look ...
0
votes
1answer
38 views

grep two searched words

I could search lines that contain two specific words using the following in multiple files: for f in $(ls *.txt); do echo ">"$f; more $f | grep word1 | grep word2 done Now, I want to write a ...
4
votes
1answer
43 views

Find the files between two folder dates in linux?

I need to find the folder names along with the file names which has my string in their contents. I am in this directory "/data/queue/data" and I have lot of folders in the same directory and inside ...
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
71 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
114 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
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
34 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 ...
0
votes
1answer
66 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 ...
1
vote
2answers
90 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: # ...
6
votes
3answers
218 views

Print unmatched patterns, using grep with patterns from file

patterns.txt: "BananaOpinion" "ExitWarning" "SomeMessage" "Help" "Introduction" "MessageToUser" Strings.xml <string name="Introduction">One day there was an apple that went to the ...
9
votes
3answers
684 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 ...
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 ...
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 ...
3
votes
1answer
45 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 ...
1
vote
3answers
140 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
2answers
70 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 ...
3
votes
1answer
42 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 ...