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

learn more… | top users | synonyms

0
votes
2answers
17 views

How to lists all users who logged in on a specific day using grep and last

Hey I'm new to Linux and I'm using Ubuntu right now. However I need to answer this question: Write a command or sequence of commands that lists all users who logged in on a monday by using last and ...
0
votes
1answer
20 views

Searching path as search pattern in grep command

I have saved the path in the variable . var="/home/myfolder/subfolder" Need to search whether the path in available in a text file using grep. grep -l '${var}' * >abc.txt I'm trying to list ...
1
vote
3answers
32 views

Quickly find all files that start with a given string

I'm writing a command to find broken Cygwin symlinks. Right now, I'm using: egrep -rnw . -e "^\!<symlink>" But this isn't very efficient. I only care if the file starts with ...
3
votes
3answers
32 views

With find -exec grep, how to print only basename or split filename/line content on separate lines?

I'm looking at source files. For PureBasic actually, but whatever the language, there are common elements involved. In my case, the command would be cover extensions pb, pbi, pbf, and pbp: find . ...
1
vote
1answer
26 views

Excluding nested directories with grep

I would like to exclude a nested directory from my grep searches, such as /path/to/file. For example: jake@jake-laptop:~/test$ egrep -r --exclude-dir="path" "hello" . jake@jake-laptop:~/test$ egrep ...
2
votes
1answer
31 views

Using individual lines from grep outputs

I'm trying to grab lines from grep and sorting them into another command, the command I'm using for grepping atm is as follows (hasn't yet been chopped enough for what I will be using it, but this ...
7
votes
4answers
203 views

How to grep -v and also exclude the next line after the match?

How to filter out 2 lines for each line matching the grep regex? this is my minimal test: SomeTestAAAA EndTest SomeTestABCD EndTest SomeTestDEFG EndTest SomeTestAABC EndTest SomeTestACDF EndTest ...
3
votes
2answers
81 views

Using grep to print all of the matching strings not separated by a space

I'm looking through a text file of emails and trying to get a list of ones from a certain domain. I'm running: grep -oh "\w*domain.com\w*" file.txt This finds the lines, but only prints that ...
1
vote
1answer
16 views

Wanted to grep the BINARY.ear md5sum value inside the md5sum.txt file

I have a file called md5sum.txt which contain below f64e7c803e4fb1207b785dff19232a1e AM-BINARY.ear 1403519c6276b2e446d2c8cef3be0e5d BINARY.ear I want to grep only the md5sum value of BINARY.ear, ...
0
votes
1answer
37 views

Print concat vars inside loop

I have a code like this: cat input | while read p; do lynx -dump "www.xyz.com/p?=$p" | grep -m 1 -A 1 "Hello" | awk -F: '{print $2}' >> output done Where the content looks like this: [$p ...
0
votes
1answer
16 views

Suppress specific instances of search key in grep

This may have been asked before but I couldn't find it. I am grepping a lot of data files for "NaN" to search for errors; the problem is that if "NaN" appears once in a file, in all likelihood it will ...
1
vote
4answers
25 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
21 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
25 views

Searching inside archives for specific files and patterns [duplicate]

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 ...
0
votes
1answer
60 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
1answer
8 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 ...
0
votes
1answer
56 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 ...
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.
1
vote
2answers
68 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 ...
0
votes
1answer
7 views

Find line within file matching pattern and make a substitution

I'm trying to simplify my life here but I'm stuck. I have a file containing multiple lines. Each line has a user and a number. I'd like to know a bash one-liner to search for a user and change the ...
0
votes
2answers
32 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 ...
0
votes
2answers
18 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 ...
-2
votes
2answers
98 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 ...
1
vote
2answers
78 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 ...
0
votes
2answers
39 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 ...
0
votes
2answers
35 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 = ...
1
vote
1answer
63 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 ...
0
votes
1answer
46 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
52 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
125 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: ...
0
votes
1answer
58 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 ...
1
vote
3answers
39 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
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
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
1answer
33 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 ...
1
vote
1answer
67 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 ...
2
votes
3answers
202 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 ...
0
votes
1answer
45 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
41 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 ...
2
votes
2answers
74 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 ...
4
votes
2answers
203 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 ...
1
vote
1answer
31 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 ...
4
votes
3answers
281 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 ? ...
1
vote
2answers
42 views

Extract columns of a string using grep

I need to extract from /proc/net/dev the second and tenth columns separated by spaces. In other words, the number of received and transmitted bytes. Is it possible to do this using grep and ...
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 ...
0
votes
2answers
30 views

How could I run -exec on find command after | grep

I am on a remote machine attempting to move all loader.gif files into a /Pictures folder find . -iname *.gif | grep loader shows four file I would like to move, naturally I tried: find . -iname *.gif ...