Questions tagged [grep]

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

The grep utility searches a pattern (regular expression) in a text file. There are many options to control how matches are performed and how to display matches.

External references

Tutorials

Further reading

See also grep on Unix & Linux Stack Exchange for more detailed reading.

326 questions
0
votes
1 answer

get a specific line from in linux using grep

Hello I am new to linux and grep and awk commands. I am trying to get the number value from this string variable and then store it in another variable. var1="Version must be incremented on update. Current version is: 532" var2=var1 | grep "?" What…
Alex
  • 172
  • 1
  • 1
  • 8
0
votes
3 answers

Apache Logs / Grep Command Help Needed

I need to be able to see all requests made by an IP in a given day. I'm not familiar with grep and was wondering if anyone could give me a hand.
Jeff
0
votes
2 answers

Any way to avoid using `grep -v`

When performing a grep filtering across pipes, as in the following example, $ ps -ef | grep 24604 username 18660 24604 0 16:38 pts/3 00:00:00 ps -ef username 18661 24604 0 16:38 pts/3 00:00:00 grep --color=auto 24604 username 24604…
boardrider
  • 949
  • 2
  • 18
  • 29
0
votes
1 answer

Grep returns nothing

This is the grep command I used grep -ic address log* The output is 0. I know for a fact that there are more than 60 occurrences of the word address in the log file. But I still get 0. Now, I copied the contents of the log into a new file log2 …
searcot jabali
  • 281
  • 1
  • 2
  • 6
0
votes
1 answer

grep multiple occurrences with intervening lines

I'd like to do the following: Given a file with many lines, several of which match a pattern, output the first matching line, the last matching line, and all the lines in between (I want them in their original order, I don't mean I want to rearrange…
user415889
0
votes
1 answer

Grepping a single line from iftop

iftop -t -L1 -s1 Output: iftop -t -L1 -s1 | grep "Total send and receive rate:" Output: How can I grep just the "Total send and receive state:" line?
JustAGuy
  • 639
  • 3
  • 23
  • 38
0
votes
1 answer

Argument list too long with grep

Normally to search and replace a string in a selection of files, I would find with: grep -rl 'pattern' . This works fine unless you have a LOT of matches. Anyway, I was looking around and found a suggestion of using find instead: find /root/path…
Andrew Newby
  • 1,102
  • 2
  • 25
  • 58
0
votes
1 answer

Trying to do grep and sed from a file and push the output into a variable

Can we do grep and sed from a file and push the output into a variable grep "^/dev/disk/by-id/scsi-*" /tmp/disks.txt | sed '{'s/=.*//'}' Output would be like…
Jacky
  • 3
  • 3
0
votes
1 answer

More elegant ps aux | grep [g]rep do not work

I am running the command: ps -ef | grep [p]ts/1 The result is: root 13820 1733 0 14:19 ? 00:00:00 sshd: root@pts/1 root 13822 13820 0 14:19 pts/1 00:00:00 -bash root 15847 13822 0 15:32 pts/1 00:00:00 ps -ef root …
Iulian
  • 3
  • 2
0
votes
1 answer

how to compare and move the matched string files in different locations

I have a two different .zip files in /tmp/1/ and /tmp/2 I want to compare these two different location files and move the matched string files into…
Booth
  • 488
  • 2
  • 4
  • 11
0
votes
2 answers

How to kill/close log files that are open through lsof grep deleted?

I have a deleted a large log file from our servers. so I executed this command to validate. lsof -nP | grep '(deleted)' and this showed up. how can I permanently delete the results fo this lsof? I need to recliam the needed space on our hardrive
KyelJmD
  • 101
  • 1
  • 3
0
votes
2 answers

Using GREP to Find Text in Files

I'm trying to use grep to find a specific line of PHP code I know for certain is present in several files, but all I get back is an empty result. Please advise on how I need to modify my grep query: sudo grep -ilr 'if (isset($_COOKIE["id"]))…
GTS Joe
  • 199
  • 2
  • 10
0
votes
1 answer

grep the result of cdrecord or wodim

I would like to parse the result/progress of a running cdrecord -v burn process. What I tried so far was cdrecord -v dev=/dev/sr0 -data foo.iso 2>&1 | grep -E 'Track [0-9]+:.*written'. Unfortunately, the command above won't show anything until the…
mefiX
  • 101
  • 2
0
votes
1 answer

delete a line if it contain a particular match from a file in bash

I have a file contain lines like the following. 10 TEST NO SOMETHING 20 TEST YES SOMETHING 101 TEST YES SOMETHING 100 TEST NO SOMETHING How can I delete only the line that has 10 at the beginning using sed or any other tool…
Vishnu
  • 711
  • 2
  • 8
  • 15
0
votes
1 answer

Unable to use grep regex to search for filename containing period

Ubuntu 14.x. Using grep to search for all files linuxtest-client2. This includes multiple file extensions (csr, crt, key). When I grep for the middle portion of the filename, "2.", it also returns lines that contain "2" in addition to "2." when…
lobi
  • 1,083
  • 2
  • 15
  • 30