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
1
vote
1 answer

Regular expressions in GREP

I have an .xml file. The tags inside are: Product Now, I have 20 000 tags like this in the file. One tag however, starts properly but it is missing a proper closing tag. How can I find which line starts properly but does not end with…
Stole
  • 111
  • 1
1
vote
5 answers

Extracting lines from a file based on prefix

I need to extract all lines from file2 that begin with an id # prefix contained in file1. File 1 is single column like: 324 399 408 135236 321590 File 2 is multi-column like: 1 [tab] 108 [tab] Anarchist [tab] 103985 ... 324 [tab] 309 [tab] Melodies…
Poe
  • 321
  • 1
  • 5
  • 18
1
vote
3 answers

How do I search by multiple keywords when using awk or grep?

I have a collection of files. I want to search through them all with grep to find all and only those which contain anywhere within them both the strings keyword1 and keyword2. I would also like to know how to do this with awk.
telnet
  • 279
  • 1
  • 3
  • 4
1
vote
3 answers

Saving the out of tail

The following does not work... tail -f /var/log/mysql/general.log | grep Connect > /home/myfile.txt If I remove the "-f" switch then I am able to save the output to a text file, but it does not work wile tail is running. Nor does tee works tail -f…
shantanuo
  • 3,579
  • 8
  • 49
  • 66
1
vote
1 answer

Using Find, Grep, Awk, or Sed To Rename Server After Cloning

My client tells me they have cloned a VM in VMWare of an Ubuntu Linux server. Now it's my job to get into all the files and find out what still has the old server name of "bishop" and change it to something else. Also, the IP address is changed and…
ServerChecker
  • 1,518
  • 2
  • 14
  • 35
1
vote
1 answer

redirecting "tail --follow=name | grep" to a file

Here is my scenario: I have a log file that is being wrote too by an application. The log file is named "alarms.log". I want to tail the file for a certain string and redirect that to a file called alarms.log.test. So i am using the below…
prolink007
  • 121
  • 6
1
vote
0 answers

How to define mail from and host settings in Websphere 6.1 for Java application

Working with some older WAS 6.1 hosts (fix pack 25), and have a java app that sends mail from one host with a mail from field: nobody@nosuchhost.nosuchdomain.com [mailto:nobody@nosuchhost.nosuchdomain.com] In another environment, it's sending mail…
RussMcGrindle
  • 371
  • 2
  • 6
1
vote
2 answers

Need help with grep urgently to comply with subpoena request

I am not a system administrator but I run a little website and today I have received a subpoena request from police, in order to comply I need to extract IP addresses from our server logs for needed time. This is my problem: 1 I have…
Andrey
  • 11
  • 2
1
vote
4 answers

How I can tell grep to search in file that I have permission?

When I call cd / grep -r "some_str" . then I see lots of files printed on the screen and in the end of the line I see ": Permission denied". How I can tell the bash to search only in file that I have permission. This will be obviously faster then…
Narek
  • 245
  • 1
  • 4
  • 15
1
vote
2 answers

finding a group of string common in two files

I have used diff command in past.I faced a situation to which I did not had a clue here are some text strings (which can be stored in a…
Registered User
  • 1,463
  • 5
  • 18
  • 37
1
vote
1 answer

Need help on awk/sed/ perl pattern with regex / grep

Sample file output from grep file1:my $dbh = DBI->connect("dbi:mysql:$database_name", $DB_USER, $DB_PASSWD) file2:($dbc,$rc) = mysql_connect($mysql_host,$mysql_user,$mysql_password); The awk pattern should get values databasename, DB_USER And…
1
vote
4 answers

Locate a particular string in a directory

I want to do the following: cat *.xml | grep some_string_here This tells me if a particular string exists in an xml file in a directory. Unfortunately it does not tell me which file. how can I do this better? cat command does not see me to have an…
1
vote
4 answers

grep/list bash recursive

parts = grep "/root/backups/*" for part in $parts do echo $part rm -rf $part #delete done I basically need to iterate through a folder and return every item in the folder using a Bash script. Unable to get working via grep, although may be…
James
  • 171
  • 1
  • 3
  • 15
1
vote
2 answers

Getting data from log file

I'd like to get the memory usage from the following log entries. It's the number right after 200 for the URL. I'd like to get a list of highest memory usage first, like top 10. I think I'd use grep for this, right? 178.0.140.206 - -…
Ben
  • 3,800
  • 18
  • 65
  • 96
1
vote
2 answers

Passing a file with multiple patterns to grep

Let's say we have two files. match.txt: A file containing patterns to match: fed ghi tsr qpo data.txt: A file containing lines of text: abc fed ghi jkl mno pqr stu vwx zyx wvu tsr qpo Now, I want to issue a grep command that should return the…