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

learn more… | top users | synonyms

0
votes
1answer
38 views

Avoiding glob expansion in fgrep string

I'm working on a Busybox distro that lacks the crontab command. I want to create a bash script that updates root's crontab file with jobs listed in a text file. I've got most of the script working, ...
0
votes
3answers
46 views

filter data by column's value

I want to search only lines where a column start with 03: (hours), but while using below command, showing all the rows where value contain 03. Its an example the data is pretty much huge in a file. ...
0
votes
1answer
37 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> &...
176
votes
6answers
384k views

How do I grep for multiple patterns?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
30
votes
3answers
37k views

How to run grep with multiple AND patterns?

I would like to get the multi pattern match with implicit AND between patterns, i.e. equivalent to running several greps in a sequence: grep pattern1 | grep pattern2 | ... So how to convert it to ...
0
votes
0answers
32 views

Output text between two strings [duplicate]

I have nmap output that is in a format similar to the following: Nmap scan report for 192.168.2.1 Host is up, received user-set (0.0055s latency). 23/tcp closed telnet reset ttl 55 Nmap ...
1
vote
1answer
57 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 ...
4
votes
2answers
3k 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 ...
-1
votes
1answer
55 views

How to grep and treat meta character as normal character? [on hold]

I am trying to recursively find some pattern which contains meta character. Pattern that I searching for is template <int N> I have tried : grep -F -lir "template <int N>" * # ...
7
votes
1answer
138 views

How to extract the string between two \n in a file

I have a file with pattern <span class="WebRupee">Rs.</span>\n29\n<br/><font style="font-size:smaller;font-weight:normal">\n3 days\n</font></td>, <td class=...
3
votes
2answers
58 views

Echo the list of process not running

I have developed a script, the script refers to a file to start the required processes on that server. The script times out after 180 secs. At the end of the script I would like to display the ...
4
votes
5answers
72 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
0answers
42 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
66 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
499 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
90k 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 | ...
5
votes
4answers
492 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
98 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. ...
7
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
232 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
24 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
223 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
65 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
54 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
561 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
247 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
27 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
34 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
410 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
45 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
69 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
132 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
86 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
77k 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
425 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
86 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
36 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
69 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
114 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
193 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,...