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

learn more… | top users | synonyms

1
vote
1answer
2 views

Outputting PID of Rails server(s) with ps aux | grep - breaks when put into an alias?

I'm trying to create an alias for an unwieldy command I'm using to output the PID and some other information about two rails servers I have running. When I simply run the command in terminal (over ...
1
vote
4answers
19 views

Match regular expression between delimiters

I have a file with several different lines. I'm looking for lines that contain(more or less) pattern like this: \[.*<.*>.*\] In other words, I want the lines that have <something> ...
0
votes
0answers
13 views

Sort Checkpoint Firewall log into easier output

I am trying to sort out this log: Aug 27 01:23:38 1.1.1.1/1.1.1.1/1.1.1.1 fw1-loggrabber[0000]: loc=12569|time=2015-08-27 ...
1
vote
1answer
24 views

Searching inside archives for specific files and patterns

Is it possible to grep inside a bunch of archives with regular expressions on both the names of the files they contain and the contents of those files? I would like to know which files in which ...
1
vote
1answer
24 views

finding directory entries that contain at least one subdirectory from a list

I have a file which contains directories and subdirectories and I need to search for lines which are subdirectories. I used the grep command to perform the action but it does not work. Can you please ...
19
votes
9answers
3k views

Grep lines but let the first line through [duplicate]

Consider the following output from df. Filesystem Size Used Avail Use% Mounted on /dev/sda1 23G 6.1G 16G 29% / udev 10M 0 10M 0% /dev tmpfs 397M 420K ...
1
vote
2answers
63 views

Stop grep after Nth files matched

I have many files I need to search for some string. I'm using grep -rl 'pattern' * to find files that contain the pattern. However, I'm only interested in file count - if string occurs in more than N ...
4
votes
2answers
189 views

grep string where next line does not contain string

I want to search all files inside a directory and its subdirectories for lines containing a certain string, but I want to exclude those results that contain a different certain string in the line ...
0
votes
1answer
49 views

SED - Find and replace with special characters (#, , % )

I'm aware that this is a really simple question, but I'm struggling to find a solution to this . I need to automatically find and replace in the /etc/aliases file the following section: # Person ...
1
vote
3answers
36 views

How to rewrite grep call from Linux to AIX

In my Linux system in fgrep I am using atributes -m 500 -C 0. But on AIX I didnt see these arguments. So how should I rewrite it? I just read to use awk instead of fgrep but I don't know how.
0
votes
1answer
52 views

How to grep the following lines from a file?

I have a file which has the names of many files in a directory in the following format: A20150824.0950-0955_jambala_CcnActiveSessionCounterJob A20150824.0945-0950_jambala_CcnActiveSessionCounterJob ...
3
votes
3answers
885 views

Which is a better way to search- find with regex or find with grep?

Of these two ways of searching a file recursively in all the subdirectories, which is faster / better ? find . -regex ".*/.*abc.*" or find . | grep ".*abc.*"
0
votes
2answers
31 views

How to use if with grep -x

This is my code: if grep -x $idle | grep -x $dead | grep -x $busy ./Event.log then echo " Events are running Successfully" >> ./Event.log else echo "One or more Events are down. Check ...
4
votes
2answers
2k views

grep one line before the match plus the match

zzzzzzzzz aaaaaaaaa bbbbbbbbb & ccccccccc & ddddddddd hhhhhhhhh eeeeeeeee fffffffff & ggggggggg & in the above line, what i want is to grep/sed/awk (any method is fine) line that ...
-2
votes
2answers
97 views

Grouping input using awk,sed,grep

I have an input file as below: 1001 Ivanov I.I: chess 2021 Petrov P.P: chess, football 3352 Sidorov S.S: 1000 Putin V.V: judo 8773 Schwarzenegger A: judo, chess, football I expect ...
0
votes
2answers
16 views

Match a word with optional delimiters with sed, grep and PCRE

How do I match a word with optional delimiters? Say I have a file named file a b "a" "a c and I want to match only quoted or unquoted a (I don't want to match "a). I'd like to do such match with ...
4
votes
6answers
200 views

Append something to each list in a file

I have a file, lists.txt, that looks like this: // stuff at beginning of file var list1 = new Array(); i = 0; list1[i++] = 'a'; list1[i++] = 'b'; ... list1[i++] = 'z'; var list2 = new Array(); i = ...
1
vote
1answer
305 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
vote
2answers
75 views

grep first column uniq values

Two columns A and B: Column A have repeated ids and column B has different values for each corresponding repeated value. I would like to read every uniq value from Column A with only the first hit ...
14
votes
1answer
3k views

grep inside less?

I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event ...
0
votes
1answer
117 views

What does this “matching lines means”?

The grep manual says "By default, grep prints the matching lines.". What does this matching lines says. When I tried its prints the whole paragraph containing the pattern.
0
votes
2answers
36 views

Search the value from a dynamic file and pass to a variable in HTML [closed]

I have the following file below with the format and I want to pass the value to HTML BE64533-A0E1-4F98-A91F-02C1D0 column=ABC_Received:ABC_Structure_Type, timestamp=1439978656596, **value=ASCII** ...
1
vote
3answers
54 views

Find lines in (muliple) files that contain the given line in an input file

So, if I have a number of files like the following: file1: 123 456 789 012 file2: line1 922 line2 392 line3 456 line5 291 line6 201 ... file3: line1 111 line2 123 line3 19 line5 542 ...
1
vote
1answer
61 views

How to check for specific strings in files of a large directory

I have a rather large directory, and I like to search the files for occurrence of specific strings. I have a list of about 30 strings, and my directory is 1.3G. I tried adding all the strings to a ...
10
votes
2answers
949 views

grep: display filename once, then display context with line numbers

Our source code has error codes scattered throughout. Finding them is easy with grep, but I'd like a bash function find_code that I can execute (eg. find_code ####) which will provide output along ...
0
votes
2answers
30 views

AWK, SED or GREP for extracting data from HTML file

Can anyone tell me which is best to use to extract the following data from a html file which was received with curl . <script>document.getElementById("test-summary").innerHTML = ...
8
votes
6answers
31k views

How to search for a word in entire content of a directory in linux

need to search for something in entire content I am trying: find . | xargs grep word I get error: xargs: unterminated quote How to achieve this?
0
votes
3answers
253 views

Unix grep confusion

I am doing an assignment for school and using putty to complete the assignment. The format of the assignment does not allow for much variation and thus only one answer is sufficient enough to allow me ...
0
votes
1answer
2k views

How to execute grep in tcl for getting XYZ-123 type pattern

How can I execute this grep command in TCL? grep '[A-Z][A-Z][A-Z]\-[0-9][0-9][0-9]' file1 > file2
0
votes
1answer
44 views

How to use grep with does not contain

In my bash script I'm trying to print a line if a certain string does not exist in a file. if grep -q "$user2" /etc/passwd; then echo "User does exist!!" this is how i wrote it if i wanted the ...
2
votes
2answers
50 views

Best way to grep big binary file?

What is the fastest way to grep 400gb binary file? I need one txt file from hdd dump and i know some strings from it and want to find this file in dump. I tried to use grep -a -C 10 searchstring but ...
1
vote
4answers
118 views

grep command to extract certain word only

I have a big report with many IP address shown in random lines. All the IP address start out with 192.168. I would like to extract only the Ip addresses and get a report that looks like: ...
1
vote
3answers
38 views

Remove words (letters followed by space) from a specific column

I have a file and the format is as follows: cat dog AHF123432 | 123432 | dhfshfjdh lion AFG23412 |23412 | dfshjhfjdhj I need to remove those words from first column which contains only alphabets ...
0
votes
1answer
57 views

What's wrong with this grep?

> output2.txt cd # some directory i'm trying to search find views/shared -type f -name "*.js" -print0 | while IFS= read -r -d $'\0' line; do echo -n "${line%.js}" | tee -a ...
0
votes
0answers
23 views

How to print line numbers using sgrep

I have a large text file : file_1 about 400 MB I have another text file : file_2 which is 7 MB I need to find the strings of file_2 in file_1 and write their matching line numbers to an output file. ...
3
votes
3answers
6k views

How to grep for same string but multiple files at the same time?

I have a set of log files that I need to review and I would like to search specific strings on the same files at once Is this possible? Currently I am using grep -E ...
1
vote
1answer
65 views

POSIX-compliant recursive grep with no errors for inaccessible directories

What script would allow me to grep a keyword and print the filename containing the keyword inside the file content , for example 'Carhart' inside all .sas files in all subdirectories, I tried ...
3
votes
1answer
41 views

What is the effect of the underscore in [A-Z] [_a-zA-Z0-9]*?

In regards to regular-expressions what is the effect of the underscore in [A-Z][_a-zA-Z0-9]*
0
votes
1answer
39 views

How to get a X line from file1 and Y line from file2 using shell command?

In file 1, 'Server restoration is complete now. It will be operational within few seconds. Please keep all the log file once the restoration is complete.' In file 2, 'Restoration was successfully ...
2
votes
3answers
194 views

How can I exclude all “permission denied” messages from “find” in Solaris

Hi previous questions on this topic contain answers for Linux but does not work for Solaris 10. find . ! -readable -prune Does not work in solaris since -readable is not POSIX. What is the POSIX ...
2
votes
1answer
32 views

Cp files into subdirectory with find -exec

Why is this command not copying the 17 .png files into a sub-directory within my current directory? $ find . -maxdepth 1 -mtime -3 | wc -l 17 $ find . -maxdepth 1 -mtime -3 -print0 | grep -z loader ...
3
votes
1answer
5k views

How do I use grep to find a text string in files in sub folders of a parent folder without -r switch

I'm using Solaris 10 and have two grep versions one in /usr/bin and one in /usr/xpg4/bin. I have been searching for an answer on how to search for text within files within sub folders of a parent ...
0
votes
1answer
44 views

Grep all strings from several binary files into one txt file

I've decided to play around dumping all process memory of couple utilities in order to find out, how much trace of sensitive info an attacker could theoretically obtain from app's memory. I've found ...
-1
votes
1answer
38 views

Why does grep goes into blocking stage? [closed]

I am making a test My task will be one child pipelining the output to the input of another another child. I am using ps -ef as the first command(by using execlp()) and grep root as the second ...
4
votes
2answers
66 views

Find if any line of a file is a subset of data in another file

I have a file file1.txt with the following data: MIME_HTML_ONLY SUSPICIOUS_RECIPS SORTED_RECIPS HFILTER_HELO_5 and another file file2.txt with lines as: HFILTER_FROM_BOUNCE FORGED_OUTLOOK_HTML ...
12
votes
3answers
4k views

Online grep exercises?

Are there any online grep tutorials that would feature some online tool for performing exercises? For example, having some predefined text sample and being told what patterns to find and so forth? It ...
2
votes
2answers
70 views

search for exact string in unix

I have a file, xyz.txt, which has one string per line. How do I search xyz.txt for an exact match? I get an input string, eg. defabc, from another app. If defabc is found, it should return true, else ...
1
vote
1answer
30 views

Get the filename that the record come from

I have a huge number of .gz files, which being uncompressed using zcat together. I am looking to get from where each record came from, as below example: File1: 1,2,3,4,5,6,7,NEW,9,10,11,12 ...
0
votes
1answer
45 views

AWK summary file from a filtered list

I have 2 files, the first being a file of records that tell me which rows from the second file I am interested in (I'll call this the FILTER_FILE). This file can contain duplicate lines and I only ...
4
votes
3answers
279 views

Grep all at once

The script I have receives arguments and needs to grep through another file. Script loops through every argument. Is there a way to collect the arguments in a single search string and grep with OR ? ...