08-30-2010
grep for string "and" string in a file
Hi,
I am trying to look for two different strings in a file using an "AND" operator. For instance...
File 1.txt
woof
meow
File 2.txt
woof
bark
I want to do a search in the directory to give me the name of the file that contains both "woof" and "meow" on different lines. So in this example I would want the command to return "File 1.txt"
I tried..
grep "woof" | grep "meow" -H *.txt
This is doing an OR operation which is not what I want...and returns all the files that contain either "woof" or "meow"..
Any help is appreciated...
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
hello,
i have an statement which i have to correct because it shows the wrong result.
i want to search an excat string in another string, command "grep" shows the wrong result:
example:
STRINGS="string1 string2 string3"
search_string="string"
incorrect:
if
then
echo "not... (0 Replies)
Discussion started by: bora99
0 Replies
2. Shell Programming and Scripting
input string="3MMTQSZ348GGMZRQWMJM4SD6M"
output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M"
using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies
3. Shell Programming and Scripting
This is the way
sed -i 's/home/$USER/.config/hello_there//g' /home/$USER/.gnomerc
But, as far as I saw you cannot add any "/" in the string you want to remove....
So, what should I do in order to remove this path (which contains "/") ?:confused: (7 Replies)
Discussion started by: hakermania
7 Replies
4. Shell Programming and Scripting
I have a file that contains the 2 following lines (from /proc/mounts)
/dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0
/dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0
I need to match the string in the second column exactly so that only one result is returned, e.g.
> grep... (2 Replies)
Discussion started by: jelloir
2 Replies
5. UNIX for Advanced & Expert Users
How can you grep for 2 string with an "AND" operator? I know you can always pipe your first grep through another grep but I was hoping there is a way to do that with an "AND" operator. (3 Replies)
Discussion started by: cokedude
3 Replies
6. Shell Programming and Scripting
logs:
"/home/abc/public_html/index.php"
"/home/abc/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
how to use "cut" or "awk" or "sed" to get the following result:
abc
abc
xyz
xyz
xyz (8 Replies)
Discussion started by: timmywong
8 Replies
7. Shell Programming and Scripting
I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here.
I have following script (called out_to_streams.csh):
#!/bin/tcsh -f
echo Redirected to STDOUT > /dev/stdout
echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies
8. Shell Programming and Scripting
Hello.
Following recommendations for one of my threads, this is working perfectly :
#!/bin/bash
CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" )
Now I need a grep success for some thing like :
#!/bin/bash
CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies
9. Shell Programming and Scripting
Platform: Oracle Linux 6.3
From a log file, I want to grep all lines with the pattern "TNS-" but I want to skip those with the pattern "TNS-12514" . How can I do this ? (3 Replies)
Discussion started by: John K
3 Replies
10. Shell Programming and Scripting
Dear Ladies & Gents,
I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out:
for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies
LEARN ABOUT DEBIAN
file::sharedir::par
File::ShareDir::PAR(3pm) User Contributed Perl Documentation File::ShareDir::PAR(3pm)
NAME
File::ShareDir::PAR - File::ShareDir with PAR support
SYNOPSIS
use File::SharedDir::PAR ':ALL';
# exact same interface as the normal File::ShareDir:
# Where are distribution-level shared data files kept
$dir = dist_dir('File-ShareDir');
# Where are module-level shared data files kept
$dir = module_dir('File::ShareDir');
# Find a specific file in our dist/module shared dir
$file = dist_file( 'File-ShareDir', 'file/name.txt');
$file = module_file('File::ShareDir', 'file/name.txt');
# Like module_file, but search up the inheritance tree
$file = class_file( 'Foo::Bar', 'file/name.txt' );
You may choose to install the "File::ShareDir::PAR" functions into "File::ShareDir" so that they become available globally. In that case,
you must do the following before anybody can import functions from "File::ShareDir":
use File::ShareDir::PAR 'global';
WARNING
This module contains highly experimental code. If you want to load modules from ".par" files using PAR and then access their shared
directory using "File::ShareDir", you probably have no choice but to use it. But beware, here be dragons.
DESCRIPTION
"File::ShareDir::PAR" provides the same functionality as File::ShareDir but tries hard to be compatible with PAR packaged applications.
The problem is, that the concept of having a distribution or module specific share directory becomes a little hazy when you're loading
everything from a single file. PAR uses an @INC hook to intercept any attempt to load a module. File::ShareDir uses the directory
structure that is typically found in the directories that are listed in @INC for storing the shared data. In a "PAR" environment, this is
not necessarily possible.
When you call one of the functions that this module provides, it will take care to search in any of the currently loaded ".par" files
before scanning @INC. This is the same order of preference you get for loading modules when PAR is in effect. If the path or file you are
asking for is found in one of the loaded ".par" files, that containing ".par" file is extracted and the path returned will point to the
extracted copy on disk.
Depending on how you're using PAR, the files that are extracted this way are either cleaned up after program termination or cached for
further executions. Either way, you're safe if you use the shared data as read-only data. If you write to it, your changes may be lost
after the program ends.
For any further usage information, including the list of exportable functions, please refer to the documentation of File::ShareDir.
SUPPORT
Bugs should always be submitted via the CPAN bug tracker
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-ShareDir-PAR>
For other issues, contact the PAR mailing list: <par@perl.org>
AUTHOR
Steffen Mueller <smueller@cpan.org>
The code was adapted from Adam Kennedy's work on "File::ShareDir"
SEE ALSO
File::ShareDir, File::HomeDir, Module::Install, Module::Install::Share
COPYRIGHT AND LICENSE
Copyright (c) 2008-2010 Steffen Mueller This program is free software; you can redistribute it and/or modify it under the same terms as
Perl itself.
The portions of code that were copied from "File::ShareDir" are:
Copyright (c) 2005, 2006 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as
Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl v5.10.1 2011-03-08 File::ShareDir::PAR(3pm)