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

learn more… | top users | synonyms

0
votes
1answer
39 views

Grep /var/log/maillog for email to a certain user, based only on his linux username

Level 1, beginner here. Question about grep and maillog. I have a learning environment, based on Linux CentOS, with Postfix and SquirrelMail running, but my assignment is more in general. I need to ...
2
votes
3answers
34 views

Regex search for word roots with common prefixes

I recently had a curiosity about words in the dictionary that share both "pro-" and "con-" as a prefix. So, for example, procession/concession, produce/conduce, profess/confess, progress/congress, and ...
2
votes
1answer
40 views

Grep on single line [duplicate]

I have a script that streams a pattern in a single line (no linebreaks). I want to grep stock_ticker in that line and output it as soon as I have found one. Now the script is never ending and is ...
3
votes
6answers
341 views

Grep the text which matches with a pattern

I was looking for a command which will print the selected portion of a line which matches the conditions. Eg, my text line is like this: p1=X||p2=Y||p3=X||p4=X||p5=X||p6=Y||p7=X I want to print ...
0
votes
8answers
75 views

How can I stop grep returning itself [duplicate]

# ps -ef | grep gre root 15067 63614 0 11:03 pts/0 00:00:00 grep --color=auto gre Another example # ps -ef | grep sshd root 1186 1 0 Jul26 ? 00:00:00 /usr/sbin/sshd -D root ...
-1
votes
2answers
44 views

Find file, Edit text within files

Im trying to find a file then edit the text within these files. This is what I have so far, but sadly Im not that well versed... Help Please? grep -rl "wrongtext" ~/Library/Calendars ...
2
votes
3answers
114 views

How to print the before lines of search keyword with out using grep in a gz file?

How to print the lines before a search keyword without using grep in a .gz file? ID:342N000390AAAAAAAA 07/14/15 10:26 (MV90 ) * Register Data Imported * Warning - No ...
9
votes
3answers
297 views

Equivalent command to grep binary files

I have a bunch of binaries and I know that inside these binaries there are strings I want to find. I want to do a: grep -lir "the string I am looking for" and get a list of all binaries inside a ...
2
votes
5answers
402 views

How to grep all xml files that do not begin with “<”

How can I find all xml files in the current directory and all sub directories, that do not start with < in the first line. I have tried this, but the grep doesn't work: find . -type f -name ...
2
votes
1answer
90 views

fgrep or grep -F, which one is better for portable script? [closed]

I am having this controversial commentary on this answer to a quesion whether we should use fgrep or grep with the -F switch (i.e grep -F) for portability. The points that have been came into light so ...
3
votes
2answers
65 views

comparing the first column of two files and printing the entire row of the second file if the first columns match

I have two files in these formats: file1 : air smell hand dude road cat file 2: air,4,21,01,13,3,2 smell,21,4,2,5,6 dude,1,31,42,1 road,1,4,2,1,4 cat,1,5,6,3,1 hand,1,4,2,1,6 mouse,1,3,5,6,2 ...
1
vote
2answers
45 views

Remove x lines before and y lines after nth line (which matches a pattern) in a file

I'm trying to remove a four line block from a text file if the second line matches the Regex N+. The text file is composed of many repeating 4 line formats, ie: @HEADER1 ACTGCNNNT + 583@#!NMY ...
0
votes
1answer
40 views

Grep unix for a data to find out result

i have a file, contains huge data. for example there is written "COST-> 1.00" line. and i would like to grep for example between 1.00 and 100. it includes both integer and string characters. how ...
0
votes
2answers
26 views

Replace fields in file inline

I have file (a.txt) with following contents: Redhat master 12345678 V1A 20.0/20.0.1 Windows slave 12345678 V1B 19.0/19.0.1 I want to grep line with word master and replace 4th and fifth field with ...
0
votes
2answers
35 views

grep for lines/files that contain exactly X chars

Here's the output of a grep command I ran: [user@localhost] : ~/Documents/challenge $ grep -i -e ".\{32\}" fileA fileB fileA:W0mMhUcRRnG8dcghE4qvk3JA9lGt8nDl fileB:observacion = new Observacion(); ...
0
votes
2answers
52 views

How to count the number of words of each sentences in a file using shell command?

I have text files like this: Mr.P.K.Baneerjee has visited the site today at 4.30pm The permit tag has been set in the ds busbar Opearation has been performed in presence of control engineer Opeation ...
1
vote
1answer
40 views

Recursively count occurrences of a word in identically named files in different directories

I've got several different directories that contain different versions of some files. I want to count a symbol in all versions of the same file. Here is an example of the hierarchy. directory ...
3
votes
1answer
113 views

Grep doesn't match carriage return characters

I'm trying to find lines with the carriage return character, but I'm not getting the results I'd expect. I've whittled it down to this proof-of-concept: $ uname -a CYGWIN_NT-6.1 Aodh ...
1
vote
4answers
153 views

Grep for a string in file without using pipe

I want to grep for a word in a file in the last n lines without using the pipe. grep <string> filename enables to search the filename for a string. But, I want to search for a string in the ...
0
votes
2answers
51 views

Display filenames with grep

I'm looking for a way to display the filename when using this command: cat *.tcp | grep "tcp" | grep "open" | sort | uniq Is there a way to do it?
3
votes
6answers
339 views

Grep a file on specific field

I have two files, let's say File1: Locus_1 Locus_2 Locus_3 File2: 3 3 Locus_1 Locus_40 etc_849 3 2 Locus_2 Locus_94 * 2 2 Locus_6 Locus_1 * 2 3 Locus_3,Locus_4 ...
1
vote
2answers
111 views

Grep multiple patterns and print a different number of lines below each of the patterns?

I am trying to find a way to grep/awk multiple patterns and then print a certain number of lines below the first pattern and a certain number of lines below the second pattern. For example .... ...
0
votes
0answers
37 views

print duplicate fields in different columns from two files using awk

I have two large files. I am attempting to identify and print any duplicate fields to a new file. I have a 19 columns and over 100k rows. I need to compare columns 5-19 for duplicate values. ...
0
votes
3answers
53 views

parsing out duplicate barcodes in a separate line

I've got the following data I need to parse out the duplicates from column1 into a separate file, For example, 21288003132541:cr 21288003267289:fr 21288003758683:ph 21288003758683:tag ...
-2
votes
1answer
28 views

exclude names without a comma

How do I exclude names from my list that have no comma and output them to a file? Should I use grep? Example: Charlie Chapman William, Henry Gary, Stevens Mark Twain Harry Potter Smithy, John Mon
1
vote
4answers
82 views

“head” only printing one line?

I've got a CSV file that's generated by saving as CSV from Excel. If I do "head" (or indeed "grep" or anything else) it only prints the first line: head -n 10 messy.csv 10,15,11,21 But if I open ...
2
votes
3answers
54 views

Split command and arguments, and put into variable in a bash script

I have a script that repeats the same (very long) grep command many times. I want to make the script more readable by cutting the line length, so I tried to put parts of the command into variables. ...
2
votes
4answers
79 views

Print alternating lines with conditional

Still struggling with messy logfiles. What I want is to find lines that first matching string X and then string Y. I then want to print them together. The problem is that, sometimes there is X, but no ...
1
vote
1answer
20 views

Filter screenlog with screen command

Pressing Ctrl+A, H, lets me log output of the screen command. However, the output file is too large. Is it possible to apply a grep-like filter so that I can control what gets logged? For example, I ...
7
votes
4answers
355 views

How to grep-inverse-match and exclude “before” and “after” lines

Consider a text file with the following entries: aaa bbb ccc ddd eee fff ggg hhh iii Given a pattern (e.g. fff), I would like to grep the file above to get in the output: all_lines except ...
4
votes
1answer
54 views

How can I repair a tar file where stderr got mixed with stdout?

I have a tar file that I'm trying to repair. The problem is that tar's stderr got mixed in with its stdout, so the file looks like this: % head android-1435613730.tar tar: removing leading '/' from ...
-1
votes
1answer
47 views

To sed if with and without conditions correct

I know that I may have the C package #include <stdint.h> in the first 1-30 lines. I would like to add it to lines where no previously if the file contains the word LARGE_INTEGER by GNU tools. ...
3
votes
2answers
73 views

How do I filter stdout of a program through grep while still controlling the program?

I'm trying to filter the output of the mpv media player, removing a particular line, but when I do so I am unable to control mpv with the keyboard. Here is the command: mpv FILE | grep -v 'Error ...
2
votes
3answers
109 views

Split binary data of fixed byte offset by byte position?

I have binary data which I review by xxd -ps in hex format. I notice that the byte distance is 48300 (=805*60) bytes between two headers where the separator is fafafafa. There is the beginning of ...
2
votes
1answer
20 views

Extract values from block of data

I have the below block of data. Heap after GC invocations=31 (full 3): par new generation total 131008K, used 0K [0x00000000eac00000, 0x00000000f2c00000, 0x00000000f2c00000) eden space ...
12
votes
5answers
587 views

How can I count the number of lines in a file after a grep match?

I am trying to count the number of lines after a problematic row in a csv file. I am aware I can use the grep -a # syntax to output # number of lines after a match has been found. I'm only interested ...
1
vote
2answers
59 views

How do i search for certain sections of a file and then extract only relevant information within that section?

So I have a text file that is a server report and has about 1000 lines of information in it. I'm trying to write a script that can search the report for only certain pieces of information I'm looking ...
1
vote
2answers
105 views

Search for a multiple patterns in specific column in fixed length file and output entire line

I need a command in Unix to look for a pattern in specific columns in a fixed length file and output the entire line to a different file. Example File1 2345abcdef450022677 1234sdfght350022677 ...
0
votes
1answer
50 views

Delete email addresses in .csv that are listed in a .txt file

I run the following command to keep email addresses listed in emails.txt grep -wFf emails.txt file.csv > newfile.csv But how would I change this command to remove addresses from file.csv that ...
2
votes
1answer
74 views

Match a number range with grep

I need to find all processes that have in their names a number between 100 and 200 inclusive. I tried ps -ef | grep xclock -bw '[1-2][0-9][0-9]' but that includes 299. How to suppress it and ...
1
vote
1answer
35 views

Obtaining unique lines with matching strings [duplicate]

I have a JSON like text file of records with duplicate ids that look like: {"ID":"93" , "ST":[42,77,51]} {"ID":"21" , "ST":[43,4]} {"ID":"94" , "ST":[65,11,4]} {"ID":"93" , "ST":[42,77,51,29,63]} ...
1
vote
1answer
38 views

Is my understanding correct about egrep -if file1 file2?

I am using KSH, Solaris 5.10. Suppose file1 contains a list of fruits and file2 contains list of fruits & nuts. My understanding about the following command egrep -if file1 file2 is that it ...
0
votes
2answers
49 views

Grep for regex in basename but return wholename

So say I have a list of files in a text file: ... /foo/barfoo /bar/foo/foobar /foobar/bar/foo ... I have a script that will search through this text file and, much like the locate command, I want ...
-2
votes
1answer
44 views

How to get more than 20 lines of output with grep when searching for a string with spaces [closed]

I am currently using grep like this: grep search_string search_file > output_file Here is an example: grep "ich arbeite" deu.txt > out.txt When used in this way, I only get the last 20 ...
1
vote
4answers
56 views

Find text in a file and copy it to another file

Is there any command in Linux to find text in a file and if found then copy it in another file? Using sed -i we can find text but how to copy whole line in another file?
0
votes
0answers
13 views

Postgres server start fails - netstat -ant|grep 5432 output explanation?

I'm working on a Ruby on Rails app. Hosting on Heroku with postgres. Tried running "heroku run rake db:migrate" as usual, but getting error "cannot connect,... check if something else is already ...
2
votes
3answers
39 views

grep .* returns results from .bash_history and complains about

I'm new to Linux and so far I've been playing around with some utilities, specifically the grep utility. I decided to create a new file (aptly called 'newfile') with the following content: Lady of ...
4
votes
3answers
38 views

Timing of ps piped to grep

So, this isn't a problem as such, just something I'm curious about. I'm using Linux Mint MATE which is branched off Debian. If I do: ps afx | grep abcdefg I get: 16599 pts/3 S+ 0:00 | ...
1
vote
2answers
45 views

How to use multiline as group-separator in grep?

In grep you can use --group-separator to write something in between group matches. This comes handy to make it clear what blocks do we have, especially when using -C X option to get context lines. $ ...
2
votes
1answer
27 views

Unset all ENV variables matching _PROXY

I'm trying to unset all environment variables that match _PROXY: env | grep -i _proxy | column -t -s '=' | awk '{ print $1 }' | grep -iv 'no_proxy' | xargs -0 -I variable unset variable but it's ...