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

learn more… | top users | synonyms

0
votes
2answers
14 views

extract url between 2 strings in a file

I have a file in which each line is like this "372"^""^"2015-09-03 06:59:44.475"^"NEW"^"N/A"^""^0^"105592"^"https://example-url.com"^"example-domain < MEN'S ULTRA < UltraSeriesViewAll ...
0
votes
0answers
11 views

How to add “wrappers” around methods in source code based on a pattern, using sed, awk, grep and friends

How can I add wrappers to a file based on a pattern? For instance I have the following: ... find(css_policy_form_stage3).click with_ajax_wait expect(css_coverage_type_everquote).to ...
0
votes
2answers
14 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
25 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
21 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 ...
15
votes
2answers
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 ...
3
votes
3answers
33 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 . ...
27
votes
7answers
13k 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
27 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 ...
3
votes
2answers
82 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 ...
7
votes
4answers
205 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 ...
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
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 ...
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 ...
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
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 ...
4
votes
2answers
204 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
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
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
57 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
911 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
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 ...
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
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 ...
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 ...
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
316 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
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
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
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 ...
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 ...
10
votes
2answers
955 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
36 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
32k 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
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: ...
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
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 ...
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. ...