Sponsored Content
Full Discussion: Grep to find an exact string
Top Forums Shell Programming and Scripting Grep to find an exact string Post 302994767 by Don Cragun on Monday 27th of March 2017 09:58:41 PM
Old 03-27-2017
Do you only want to find the string you're searching for at the start of a line? Or do you want to display a line if the string you're searching for appears at the end of a line?

Do all lines have two fields (as in your example)? Or, could some lines have only one field. Could some lines three or more fields?
 

10 More Discussions You Might Find Interesting

1. Solaris

Find an exact string

Hii,., Can some one guide me ...how to find a exact word or string using "grep" not a part of some other string. say if i need 321 it should not give me 3210 nor 1321 it should only give me line containing string 321 Thanks and Regards, Joy (2 Replies)
Discussion started by: gr8pals
2 Replies

2. UNIX for Dummies Questions & Answers

Find exact string

Hi Guys, File is containing data Col1 Col2 ListPrice List Price Price Average Selling Price - Actual ProjPrice Average Selling Price ProjPrice Launch Price ProjCost Cost Now i need to print col2 on the basis of col1 i.e if i Pass Price it should display only "Average... (7 Replies)
Discussion started by: Swapna173
7 Replies

3. UNIX for Dummies Questions & Answers

Matching exact string with blank space using grep

hi! i'm trying to get grep to do an exact match for the following pattern but..it's not quite working. I'm not too sure where did I get it wrong. any input is appreciated. echo "$VAR" | grep -q '^test:]name' if ; then printf "test name is not found \n" fi on... (4 Replies)
Discussion started by: jazzaddict
4 Replies

4. Shell Programming and Scripting

How to use grep to get an exact string?

Hi there, I've search this forum and find this problem could have been solved by, grep -ho "num=*" input_data The input_data is, 1\11\num1=100\num2=200\newnum1=220\\@ however, what I have got is , num1=100 num1=220 how to get the exact string, (4 Replies)
Discussion started by: liuzhencc
4 Replies

5. Shell Programming and Scripting

grep exact string from a file

Hi, I have the following output from a file zone "adm.test.com" { abc test1.db } zone "test.com" { xyz test2.db } zone "1.test.com.sg" { 1abc test3.db } zone "3.test.com.uk" { 1xyz test4.db } (6 Replies)
Discussion started by: vchee
6 Replies

6. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

7. UNIX for Dummies Questions & Answers

How to grep the exact string / word ?

Hi All, I have a text / log file which contains strings like meta777, 77, meta, 777. Now I want to write a script which can detect a string 'meta#777' in a text file & number of occurence of 'meta', number of #, number 7, 77, 777. I'm using grep -e '77' filename but no luck. It is returning... (5 Replies)
Discussion started by: adc22
5 Replies

8. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

9. Shell Programming and Scripting

Grep exact string from main string

Hi , am getting output file, it sontains the below values. ./hawk_DOM1_FIRST_ENV ./hawk_DOM2_SECOND_ENV ./hawk_DOM3_THIRD_ENV Now I need to grep the word "DOM1_FIRST_ENV","DOM2_SECOND_ENV" like that. I tired with cut -d "_". Its not working with any deleimiter. Can you please help to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

10. UNIX for Dummies Questions & Answers

How to grep exact string with quotes and variable?

As the title says I'm running a korn script in attempts to find an exact match in named.conf finddomain.ksh #!/bin/ksh # echo "********** named.conf ************" file=/var/named/named.conf for domain in `cat $1` do grep -n '"\$domain "' $file done echo "********** thezah.inc... (1 Reply)
Discussion started by: djzah
1 Replies
Mail::Mbox::MessageParser(3pm)				User Contributed Perl Documentation			    Mail::Mbox::MessageParser(3pm)

NAME
Mail::Mbox::MessageParser - A fast and simple mbox folder reader SYNOPSIS
#!/usr/bin/perl use Mail::Mbox::MessageParser; my $file_name = 'mail/saved-mail'; my $file_handle = new FileHandle($file_name); # Set up cache. (Not necessary if enable_cache is false.) Mail::Mbox::MessageParser::SETUP_CACHE( { 'file_name' => '/tmp/cache' } ); my $folder_reader = new Mail::Mbox::MessageParser( { 'file_name' => $file_name, 'file_handle' => $file_handle, 'enable_cache' => 1, 'enable_grep' => 1, } ); die $folder_reader unless ref $folder_reader; # Any newlines or such before the start of the first email my $prologue = $folder_reader->prologue; print $prologue; # This is the main loop. It's executed once for each email while(!$folder_reader->end_of_file()) { my $email = $folder_reader->read_next_email(); print $$email; } DESCRIPTION
This module implements a fast but simple mbox folder reader. One of three implementations (Cache, Grep, Perl) will be used depending on the wishes of the user and the system configuration. The first implementation is a cached-based one which stores email information about mailboxes on the file system. Subsequent accesses will be faster because no analysis of the mailbox will be needed. The second implementation is one based on GNU grep, and is significantly faster than the Perl version for mailboxes which contain very large(10MB) emails. The final implementation is a fast Perl-based one which should always be applicable. The Cache implementation is about 6 times faster than the standard Perl implementation. The Grep implementation is about 4 times faster than the standard Perl implementation. If you have GNU grep, it's best to enable both the Cache and Grep implementations. If the cache information is available, you'll get very fast speeds. Otherwise, you'll take about a 1/3 performance hit when the Grep version is used instead. The overriding requirement for this module is speed. If you wish more sophisticated parsing, use Mail::MboxParser (which is based on this module) or Mail::Box. METHODS AND FUNCTIONS SETUP_CACHE(...) SETUP_CACHE( { 'file_name' => <cache file name> } ); <cache file name> - the file name of the cache Call this function once to set up the cache before creating any parsers. You must provide the location to the cache file. There is no default value. new(...) new( { 'file_name' => <mailbox file name>, 'file_handle' => <mailbox file handle>, 'enable_cache' => <1 or 0>, 'enable_grep' => <1 or 0>, 'force_processing' => <1 or 0>, 'debug' => <1 or 0>, } ); <mailbox file name> - the file name of the mailbox <mailbox file handle> - the already opened file handle for the mailbox <enable_cache> - true to attempt to use the cache implementation <enable_grep> - true to attempt to use the grep implementation <force_processing> - true to force processing of files that look invalid <debug> - true to print some debugging information to STDERR The constructor takes either a file name or a file handle, or both. If the file handle is not defined, Mail::Mbox::MessageParser will attempt to open the file using the file name. You should always pass the file name if you have it, so that the parser can cache the mailbox information. This module will automatically decompress the mailbox as necessary. If a filename is available but the file handle is undef, the module will call either bzip2, or gzip to decompress the file in memory if the filename ends with .tz, .bz2, or .gz, respectively. If the file handle is defined, it will detect the type of compression and apply the correct decompression program. The Cache, Grep, or Perl implementation of the parser will be loaded, whichever is most appropriate. For example, the first time you use caching, there will be no cache. In this case, the grep implementation can be used instead. The cache will be updated in memory as the grep implementation parses the mailbox, and the cache will be written after the program exits. The file name is optional, in which case enable_cache and enable_grep must both be false. force_processing will cause the module to process folders that look to be binary, or whose text data doesn't look like a mailbox. Returns a reference to a Mail::Mbox::MessageParser object on success, and a scalar desribing an error on failure. ("Not a mailbox", "Can't open <filename>: <system error>", "Can't execute <uncompress command> for file <filename>" reset() Reset the filehandle and all internal state. Note that this will not work with filehandles which are streams. If there is enough demand, I may add the ability to store the previously read stream data internally so that reset() will work correctly. endline() Returns " " or " ", depending on the file format. prologue() Returns any newlines or other content at the start of the mailbox prior to the first email. end_of_file() Returns true if the end of the file has been encountered. line_number() Returns the line number for the start of the last email read. number() Returns the number of the last email read. (i.e. The first email will have a number of 1.) length() Returns the length of the last email read. offset() Returns the byte offset of the last email read. read_next_email() Returns a reference to a scalar holding the text of the next email in the mailbox, or undef at the end of the file. BUGS
No known bugs. Contact david@coppit.org for bug reports and suggestions. AUTHOR
David Coppit <david@coppit.org>. LICENSE
This software is distributed under the terms of the GPL. See the file "LICENSE" for more information. HISTORY
This code was originally part of the grepmail distribution. See http://grepmail.sf.net/ for previous versions of grepmail which included early versions of this code. SEE ALSO
Mail::MboxParser, Mail::Box perl v5.10.1 2010-06-06 Mail::Mbox::MessageParser(3pm)
All times are GMT -4. The time now is 02:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy