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

learn more… | top users | synonyms

4
votes
5answers
60 views

terminal command | grep IP

ifconfig -a | grep 10.16 inet 10.16.x.xx netmask 0xffffff00 broadcast 10.16.x.xxx inet 10.16.x.xx netmask 0xffffff80 broadcast 10.16.x.xxx I have replaced the numbers with x My aim is to ...
4
votes
4answers
2k views

How to count occurrences of all the words in all the files of a directory using grep? But with count incremented only once per word per file

I have already asked a similar question but people misunderstood what i was asking. I was asking how to generate a list of every word with a word count incremented only once per word per file. For ...
0
votes
1answer
48 views

How to actively grep log for the last 15 seconds for a phrase?

I have this bash script and inside the script, I am trying to grep a log for the words "status change" and then after I find the most recent line that contains the words "status change" (aka the most ...
0
votes
1answer
39 views

add multiple users to multiple servers [duplicate]

I have a quick bash scripting question. I'm trying to add multiple new user accounts to multiple RedHat servers in my environment. This the script I've come up with so far, but it's not quite ...
2
votes
4answers
62 views

Extract the directory path containing the file with matching string

I have multiple subdirectories at multiple levels containing a file results.out ./dir1/results.out ./dir2/dir21/results.out ./dir3/dir31/dir311/results.out Now i need to search for string1 in ...
6
votes
3answers
479 views

Grep word within a file then copy the file

I have a collection of files ( *.zip, *.txt, *.tar.gz, *.doc, ...etc ). These files reside within a path. I want to find all the files ( *.txt), then copy, only, the text files that contain specific ...
11
votes
6answers
89k views

List the files containing a particular word in their text

I would like to list the files recursively and uniquely that contain the given word. Example: Checking for word 'check', I normal do is a grep $ grep check * -R But as there are many occurrence ...
0
votes
3answers
58 views

getting a list of all lowercase words in a file

I'm trying to get a list of all lowercase words in a file. This far I've gotten to the point of getting a list with the command line cat filename.txt | tr ' ' \\n | grep -w '[[:lower:]]*' | sort -u | ...
0
votes
0answers
29 views

how to grep a tag value in xml file and print another two tag values in same xml file

I want to grep tag value of and if its 01 it must print another tag and along with its value . Sample XML file : <CustName>Unix</CustName> <CustomerId>999</CustomerId> &...
5
votes
4answers
475 views

How to check if any IP address is present in a file using shell scripting?

I have a script that generates some output. I want to check that output for any IP address like 159.143.23.12 134.12.178.131 124.143.12.132 if (IPs are found in <file>) then // bunch of ...
3
votes
2answers
92 views

Solaris ps aux comand specific output. Why for grep need use ww parameter?

I'm starting to use Oracle Solaris 11.2 SPARC. In Linux, I can write ps aux | grep *some_data* But doesn't show any result on Solaris. Instead I need to say ps auxww | grep *some_data* I had ...
10
votes
5answers
36k views

How to add a carriage return before every newline?

I have a file that only uses \n for new lines, but I need it to have \r\n for each new line. How can I do this? For example, I solved it in Vim using :%s/\n/\r\n/g, but I would like to use a script ...
-6
votes
1answer
49 views

How to determine current users who are logged in using a specific domain? | UNIX [closed]

I want to know How to determine current users who are logged in using a specific domain? For example, here is the question. Please tell according to it using the grep command and use of wc. ...
-4
votes
0answers
24 views

How to determine current users who are logged in using a specific domain? [duplicate]

I want to know How to determine current users who are logged in using a specific domain? For example, here is the question. Please tell according to it using the grep command and use of wc. ...
6
votes
1answer
5k views

remove lines where a field's value is less than or equal to 3 - sed or awk?

I need to remove every line that has a value of 2 or less in the 8th field (column). My data looks like this: 12-31 Airport 189 379 41 49.70946503 -124.91377258 2 2880 30.8 01-01 ...
3
votes
1answer
229 views

How to count occurances of phrase in grep, ignoring case?

I need to search for a name nicolas bomber with grep. Name can also be NiCoLaS BomBer. I need to run a .sh file which display the number of occurrences of that name. The command I made is this one: ...
1
vote
0answers
23 views

Using ack to effectively search and RStudio project directory

I'm interested in running ack search on a RStudio project directory that mostly contains *.R script files but also some project files and often *.git files. Directory The project folder structure ...
1
vote
3answers
64 views

How to grep/awk/sed for text in a log and display the chunk that has the text?

I'm looking for something pretty similar to this. The logs look like this: [09:44:22] [main] ERROR [url/location] - A ONE LINE ERROR [09:44:22] [main] ERROR [url/location] - Another ERROR [09:44:22]...
6
votes
1answer
220 views

Each grep result to different file

I have something like grep "keyword" -B 3 log. It show a lot of results like: some trash [GET] /orders/42 one more trash keyword and usefull info [GET] /orders/43 some trash one more trash keyword ...
0
votes
2answers
64 views

deleting lines between rows in a text file using awk or sed

I am wondering if there is a sed or awk command to delete all lines between the 'Query_' headers in column 1, if the number of lines between each header is less than 5. The following is an extract ...
1
vote
4answers
50 views

Function of second grep in `ps | grep -v | grep`

ps aux | grep firefox Lists all processes having the string "firefox" ps aux | grep -v firefox Lists all the processes without the string "firefox" ps aux | grep -v grep | grep firefox ? ...
7
votes
2answers
556 views

Grep to find the correct line, sed to change the contents, then putting it back into the original file?

I'm trying to change a single word on a specific line in a file, but I'm having some trouble connecting all together. Basically, on one line in my file there is a keyword 'firmware_revision', and on ...
1
vote
3answers
243 views

Why can't I pipe to ack?

So I've been trying to use grep to extract some stuff from a Mercurial log and trying to avoid using awk just to see if I can get by without it here, and failing because neither grep nor egrep support ...
1
vote
1answer
48 views

is it possbile to add comma in this SQL?

I have a statement like this UPDATE `test`.`scores` SET id=1 name='kobe' score=99 WHERE id=1 name='kobe' score=100 UPDATE `test`.`scores` SET id=2 name='tmac' score=70 ...
0
votes
1answer
26 views

Move files only if filename based regex does not match file in target dir

Best explained by an example: Source dir: file-a-1.txt file-b-1.txt Target dir: file-a-2.txt Expected result: file-a-2.txt file-b-1.txt Move all files from src dir to target dir only if ...
0
votes
2answers
33 views

Extracting all columns containing a list of terms

I have a data file (data.txt) with ~320 rows and ~1800 columns (1.9 MB), and I need to extract certain columns out (for all rows). The general layout of data.txt is as follows: ID ...
4
votes
5answers
405 views

Insert new lines with missing values (NA)

I would like to insert new lines in text files if there are missing values. I have for example the following text file (A.txt), for which line 5 is missing. In addition, as the file should have 12 ...
1
vote
2answers
44 views

pipe ls to grep (lines vs. “items”)

Consider the following command: ls dir1 dir2 file1 x1 x2 y2 when this output is piped into e.g. grep each file/directory is processed as an 'item'. ls | grep f file1 So obviously there is a ...
1
vote
5answers
68 views

Getting substrings in between delimiters multiple times from one string without looping

I have looked all over for a solution to this, but I couldn't find one. I am using qstat -x to pass a large string of job information. The output from qstat -x is in XML format. The substrings I am ...
3
votes
1answer
129 views

Match RH[A-ZA-Z] with grep

How can I match with grep the regex RH[A-ZA-Z], so string includes RH with two characters that both are a letter between A and Z? I tried this but without success: yum list-security --security | ...
-4
votes
4answers
79 views

How to print the the first line using grep comand?

I have a file called file.txt. How can I print the first line only using the grep command?
30
votes
4answers
76k views

Recursive grep vs find / -type f -exec grep {} \; Which is more efficient/faster?

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can ...
0
votes
1answer
16 views

exiv2 piped to grep - random inconsistent behavior

For a bunch of jpg photos, I have this (simplified) script to be able to extract the original date when the photo was taken (if different of 0000:00:00, not relevant for this case) for f in *.jpg; do ...
2
votes
2answers
47 views

help to construct grep output

I have a command I am using #cat test |grep "Ongoing Calls" |awk -F' ' '{print $3}' 40 2 As you can see it returns 2 values 40 & 2 I want to now add these together and put into a file as 42 ...
4
votes
4answers
419 views

How to obtain grep exit status into a variable

I started learning Bash a couple of days ago. I'm trying to obtain an exit status of grep expression into a variable like this: check=grep -ci 'text' file.sh and the output that I got is No ...
-1
votes
4answers
85 views

Extracting IPs from a web list

I am trying to extract IPs from a huge web generated list which contains a mix of text, IPv4 & IPv6 IPs, newlines, IP ranges etc. Below is a snippet from the list: ; Spamhaus DROP List 2016/07/...
2
votes
1answer
31 views

How to extract IP and URL from a log file

I have a long and generic squid log file. My boss is asking me to extract IP's alongside with accessed URLs. So far I can process IP's, but I need those IP's listed with the URLs accessed. Something ...
1
vote
1answer
68 views

Why getting these “Permission Denied”s in POSIX find-grep readable?

I do in Posix find $HOME +perm 0666 -type f -exec grep -l "XSym" {} \; but get this which I do not understand find: ‘/home/masi/.dbus’: Permission denied grep: /home/masi/.viminfo: Permission denied ...
3
votes
2answers
110 views

Find each line matching a pattern but print only the line above it

I need to find a string and need to print the line above it. case1: The same line won't have the more than one matching pattern ie) consider a file containing $cat > para returns between the ...
0
votes
3answers
73 views

grep for IP without last octet as 0 [duplicate]

I am trying to extract IPs from multiple web generated lists, and need to isolate the ones that do not end with 0. Eg, in the list below, it has text, regular IPs and IP ranges. What I'm trying to do ...
5
votes
5answers
191 views

How do I speed up a script based on a grep search?

There is a very large text file with two comma-separated values: 78414387,10033 78769989,12668 78771319,13677 78771340,13759 80367563,16336 81634533,10025 82878571,10196 110059366,10218 110059411,...
2
votes
1answer
120 views

Using grep to count number of occurrences for each word found in a regex pattern

I'm using the following to get number of occurrences using grep and wc. grep -iEo "(red|white|blue)" somefile.txt | wc -l However, this out puts a number. Instead I would want something like: red:...
3
votes
3answers
79 views

Basic grep/awk help - extracting all lines containing a list of terms from one file into a seperate file

I have two files genelist.txt and data.txt. genelist.txt simply contains a single column of ~500 gene names, whereas data.txt is a tab delimited file that contains ~1000 columns (the samples) and ~30,...
-3
votes
1answer
48 views

What command lines should I use for the following? [closed]

What command lines should I use for... printing a list of users running bash now in alphabetical order print the count of users who are running bash right now save the list of users who are running ...
0
votes
3answers
56 views

piped command after grep not working

I want to monitor a file. So I have tailed a file using below command, to execute a script per line. tail -3f logfile.log | grep "action.*add" | sed -u -e "s/^/'/" -e "s/$/'/" | xargs -L 1 -P 5 bash ...
14
votes
5answers
629 views

Find files that contain multiple keywords anywhere in the file

I'm looking for a way to list all files in a directory that contain the full set of keywords I'm seeking, anywhere in the file. So, the keywords need not to appear on the same line. One way to do ...
1
vote
1answer
36 views

Regular Expression ^$ not working on UNIX using grep command

I'm facing a problem in using the regular expression ^$ on UNIX. When I type grep '^hello$' text on the command line, as a result it should match the "hello" word because it is the only word on a ...
4
votes
2answers
8k views

How to grep top most frequent error messages in a unix logfile

If I have a file example apache log file How to extract the top most frequent error messages in a unix log file with no timestamps the key is most frequent error message should come on top of the ...
0
votes
3answers
39 views

Count the number of occurrences of specific number before each string in linux

I have this file : 90 1 120 1 Transition 150 1 Transition 165 1 Transition 180 1 225 1 240 1 255 1 270 1 Transition 285 1 Transition and I want this output: 1 2 2 1 3 1 4 5 5 ...
1
vote
2answers
38 views

Grep from a doubly-gzipped file

I have a file that is gzipped twice: test.gz.gz How do I grep something from the file above? I don't want to unzip it.