grep is a command-line utility that is used for searching text.

learn more… | top users | synonyms

7
votes
5answers
348 views

I need help with Grep to start at a section

I have some text files that I want to grep a section of code from. The goal I am trying to achieve is to start the view at a certain line & then be able to read anything below it. For example. In ...
0
votes
2answers
17 views

what's wrong with my grep command?

Grep works when I use is with ls | but when I try the command by itself, it just gives me a blinking cursor that never goes away on the next line (as if it's running a command). For example, I tried: ...
0
votes
1answer
33 views

Why the “service --status-all | grep mysql” get many unrelated result?

It seems weird here while running service --status-all | grep mysql why I get so many wrong result? It works fine on Centos where i am getting: mysql is running xxxxxxx This is what i am ...
0
votes
0answers
9 views

Checking two process in same port [duplicate]

I'm new to ubuntu and not have an expereince in networking so i have problem with binding port that already in use I checked it by sudo lsof -i tcp | grep LISTEN and got pid of the port to check ...
0
votes
0answers
48 views

`grep -r` command leads to kernel panic

Every time I run grep -r something . in vim command line mode, the system shows kernel panic message. And if I run it outside vim, the system totally freezes. I can do nothing. Even Ctrl-Alt F1-F12 ...
0
votes
1answer
16 views

Ubuntu grepping strings with missing spaces

let's say I had the email test1234test@test.com in a file which contains a list of emails. But, instead of having the entire email, I only had (for example) t**********t@test.com How would I grep ...
3
votes
1answer
220 views

proper syntax for grep: search a string, copy two rows above and transpose

Am new (2 days old) to Linux and grep and am stuck here. Scenario. I have data lasting more than 10yrs which I have been doing manually until I came across grep. The folders are of form \yyyy\mm\dd ie ...
4
votes
3answers
563 views

Difference in two types of command that uses grep

So, here we have two commands: cat /var/log/dpkg.log | grep " \install\ " cat /var/log/dpkg.log | grep install Why are the outputs of these commands different? And can you please explain the first ...
0
votes
1answer
48 views

search using regular expression with alternation

I'd like to search files containing G Bush, J Bush, B Bush, or H Bush The following command can achieve the goal: grep -rnE "G Bush|J Bush|B Bush|H Bush" Can we do something like grep -rnE ...
6
votes
4answers
771 views

How to escape “.” with sed or grep?

I have file with denm.xyz denm.abc denm.def denm_xyz denm_abc denm_def I want to extract the ones with . in it. I tried grep "denm\.*" file grep 'denm\.*' file sed "/denm\.*/p" file sed ...
0
votes
0answers
83 views

Freezes on restart and shutdown

Just installed Ubuntu 14.04, on Razer Blade 14 The system freezes as soon as I try to restart or shutdown. Tried to add 'pci' and 'acpi' and 'boot' to the grep, didn't help. Tried to reinstall, didn't ...
1
vote
1answer
105 views

How to search String with “\” character and to Replace it

I am Stuck into an issue regarding searching and replacing a directory path included in my thousands of file, what I want, to search those directory path in files and to replace it with new directory ...
0
votes
0answers
89 views

Log Sifting: Rewrite Logs for Human-Readable Verbage

My goal is simply to build a reworded log containing the lines where an external IP address interacted with an apache2 server. So far, I have come up with the following: #!/bin/bash # apache2 log ...
4
votes
1answer
128 views

Search files content for possible BTC key strings

I have 4 BTC addresses on two of my drives that I cant bloody find. I saved them under stupid name so they would be hard to find if someone had access to my system. Now I cant find them. Is there a ...
7
votes
3answers
535 views

Listing files with grep?

I have a directory that contains the following files: file1a file1ab file12A2 file1Ab file1ab I want to list all files that start with file1 and followed by two letter at most! The solution I ...
2
votes
3answers
1k views

Extract word from string using grep/sed/awk

I have a string 00:28:04 /usr/lib/jvm/jre/bin/java -DJDBC_CONNECTION_STRING= -Dspring.profiles.active=qa -XX:MaxPermSize=256 and want to extract the word qa that follows -Dspring.profiles.active. ...
5
votes
2answers
2k views

What does grep do?

Here is the description of grep from GNU.org: grep searches input files for lines containing a match to a given pattern list. When it finds a match in a line, it copies the line to standard output ...
10
votes
4answers
582 views

grep command and [ ]

I'm learning bash code and today I'm studying the command grep. if I run $ ps -fU user | grep thunderbird terminal shows: user 17410 1 0 10:09 ? 00:00:20 ...
0
votes
1answer
75 views

Why is grep only returning one line?

#!/bin/bash while true; do trap break SIGINT ping -w 5 10.0.0.1 | { trap '' SIGQUIT ts '%Y-%m-%d %H:%M:%S |' | grep -E 'PING|packets|rtt' | { read grep_out echo ...
10
votes
4answers
726 views

How would you count every occurrence of a term in all files in the current directory?

How would you count every occurrence of a term in all files in the current directory? - and subdirectories(?) I've read that to do this you would use grep; what is the exact command? Also, is it ...
0
votes
1answer
107 views

grep command to find 'words' that begin and end with * (e.g., *way*, *then*)

My original thinking was that this would work grep -w '\*.*\*' /path/file-name This produces some good hits but it doesn't respect the word option. I get whole lines. For example, like this ...
1
vote
1answer
45 views

Advanced Ping Script [closed]

I want to have a little script which do a ping to 8.8.8.8 every 2 seconds and put only out the time. It should also put a "#" between every time. Like this: 25.5 # 25.4 # and so on... Finally i ...
5
votes
3answers
542 views

How can I use the grep command to extract line which is the next line of greping line?

I have text file like (the specific part of the whole file); ! lat long elev (m) ! 44.5199005 11.6468000 50.4276 I need to extract second line and save ...
2
votes
2answers
170 views

Command to write all .js files to a single file?

I am trying to put all .js files in a directory and sub directories into a single file in lexical order. I have tried: grep -r --include=*.js * > dir/.filename What did I do wrong?
1
vote
2answers
28 views

Generate a log of all the installs on a system (whether apt-get/yum/pip/npm/…)

Is there a command (or specific syntax for history command) that generates (to screen or file) a log of all the installs on a system (whether they were through apt-get/yum/pip/npm/...). If possible, ...
2
votes
1answer
62 views

can you solve this? [closed]

if you have a puzzle and you want to solve it with computer... 6 characters the available characters is "NQAECFCYCPHY" what is the possible right words can you get? I tried to solve it with grep ...
15
votes
3answers
1k views

tail a log file but show only specific lines

I'm tailing a log file with -f flag. Then I'm piping this to grep, to find only lines that contain "X". That's working perfectly fine. Now I want to pipe this again into another grep, that will remove ...
1
vote
2answers
105 views

How to prevent grep from printing the same string multiple times?

If I grep a file containing the following: These are words These are words These are words These are words ...for the word These, it will print the string These are words four times. How can I ...
2
votes
3answers
1k views

Grep: The asterisk(*) doesn't always work

If I grep a document that contains the following: ThisExampleString ...for the expression This*String or *String, nothing is returned. However, This* returns the above line as expected. Whether the ...
1
vote
2answers
61 views

Can rm -rf use grep?

I am trying to use PlayOnLinux to install iTunes but my wine is clogged up, so I want to 100% delete the wine files, so is there any way to delete all files with the tag (or word) wine in them? ...
0
votes
2answers
44 views

Greping text file

I have text file: Line1 aaa Line2 aaa Line3 aaa Line4 importan info about Linux Line5 infoA Line6 infoB Line7 I would like to display line containing word "Linux" and two lines more. Regarding ...
0
votes
2answers
100 views

How to use output of grep for ping

I desperately try to use the output of grep for a script: ping dc"$(grep -o .""\[12].domain.local"" /etc/squid3/squid.conf)" ping "$(grep -o ""dc0\[12].domain.local"" /etc/squid3/squid.conf)" Both ...
0
votes
1answer
23 views

Compare and count in ubuntu

I have a file with 2 columns like this: Product Cost ab 5 ab 7 bl 1 bl 8 ce 4 I want to search for "ab" and "bl" and then need to sum up the Costs for them and ...
-6
votes
2answers
54 views

Getting number of users depending on their age [closed]

I have a text file in which there are two columns: Name Age Ashko 32 Mohan 45 arun 21 I want to get the number of users whose age is greater than 25 ex 2 in above case
0
votes
1answer
51 views

Find and print first word with matching pattern

I have a text file in which there are two columns: Name Age I want to search a part of Name in this file and on finding the first match, I want to print the whole Name Example: Name ...
2
votes
2answers
79 views

How can I cut the mac address out of DHCPDUMP?

I am trying to use dhcpdump to recognize people logging onto my home network and give them a tailor made greeting using a credential file. I cannot get the mac address out of the results of dhcpdump. ...
0
votes
1answer
118 views

Using Grep to multiple find and replace

I have lets say 90 HTML files and I have to put one new JS script link to head section each of them. Now, i could use some F&R engine of some code compiler Like: find: </head> replace it ...
0
votes
3answers
68 views

How to search through a man page?

I often want to search through a man page, however I am forced to either do: man <package> | grep <search> Or: man <package> > file.txt But there must be an easier way than ...
0
votes
4answers
198 views

Using grep in /etc/passwd to fetch list of users and system users, discriminating both

I want my grep to print a user list from /etc/passwd, and I've studied /etc/login.defs' minmax values for the ones I want my grep to fetch: # Min/max values for automatic uid selection in useradd # ...
2
votes
2answers
164 views

Why is my repetition condition with grep range not working?

Searched for a solution on SO, Ask and Unix/Linux but I am lost trying to figure out how to write a conditional with a grep range: Go through: 1-20_something 100-200_something 2-100_something ...
0
votes
2answers
71 views

shortening the output from the command ps efo cmd | grep

I want to condition on whether or not a certain process is running. The process has a very long description, more or less like /usr/bin/xpdf -remote myXpdfServer -title Bayes2_notes -papercolor ...
0
votes
2answers
104 views

Extract numbers with awk

a part of a script in awk looks like this sub(/^Mutation: {"seq-pos":/,"") && sub(/, "time":/," ") && sub(/}$/,"") { print >"fifth_"FILENAME} The aim is that given this ...
-2
votes
2answers
125 views

how to search a word or text with in command prompt

For example i have printed a mysql big table from database on cmd which has 500 fields in it .How do i search for a particular word with in command prompt. I know grep is used to search strings or ...
1
vote
2answers
216 views

How to grep for all packages used in a tex file

Assuming I want to grep all packages used in a tex file: $ grep usepackage my.tex will do, with (as far as I can see) one exception: If a package gets loaded with that many options that the author ...
0
votes
1answer
29 views

grep with limited recursion when redirect file exists

I'd like to search a word in all files under a directory recursively, and output the occurrence lines into an output file in the directory. grep -ri "my_str" ./ >> opt_file.txt However, since ...
3
votes
1answer
252 views

watch cuts off ps aux output when piped

While working on a (Python) script which is of no consequence here, I have come across a very strange behavior involving watch and ps aux, when the latter is piped to something else. I have managed ...
2
votes
1answer
277 views

How to mark matching GREP string while redirecting output to file

I am trying to use grep to find all matching strings in file and output them, in context of the line, to another file, while adding some kind of marks (ideally two asterisks) on each side of the ...
0
votes
2answers
199 views

Filter consecutive identical characters using Sed and Grep

How to find the occurrences of three consecutive and identical word characters, for example "aaa", "bbb" etc using sed and grep? I meant to find out words which have length 3 and are made from ...
2
votes
2answers
356 views

Filter lines based on length using sed and grep

How to locate lines longer than 100 and smaller than 150 characters using sed and grep
1
vote
2answers
54 views

Extracting strings from mail log

I'm trying to extract all lines of text from mail log file that contain specific string (mail address). I know using grep will allow me to search for the address mail.addres@example.org, but how do I ...