Sponsored Content
Top Forums Shell Programming and Scripting Need help to grep for a title match and then make some queries after the match Post 302406423 by durden_tyler on Monday 22nd of March 2010 08:45:30 PM
Old 03-22-2010
Here's a Perl solution:

Code:
$ 
$ 
$ cat address.txt
Address 1
1234 Drive way
New Orleans, LA
Zipcode :- 12345

Address 2
4567 Spring way
Chicago, IL
Zipcode :- 67890

Address 3
1339 Beverly Hills
Suite # 1290
Los Angeles
CA
Zipcode :- 91602 
$ 
$ 
$ ##
$ perl -lne 'chomp;
             if ($.==1 or $in==1) {$a=$_; $in=0}
             elsif (/^Zipcode :- (\d+)/) {$z=$1}
             elsif (/^\s*$/) {$in=1; print $a," ",$z}
             END {print $a," ",$z}' address.txt
Address 1 12345
Address 2 67890
Address 3 91602
$ 
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. HP-UX

Need to make disk device files match

Hi, I was wondering if there was a way to change the disk device files ex. /dev/dsk/cxtxd0 ? What I have are two HPUX 11.0 servers using MC Service Guard 11.13. A consultant attached a SAN and both servers had created the same identical LUN device files. Now I could begin creating my volume... (0 Replies)
Discussion started by: mvizza
0 Replies

2. AIX

How to make grep stop at first match

I use grep to check for a string that validates data in a file, it works great but the problem is that the file is becoming too big and gerp has started hurting the response time to users. Since I only need to find the first occurrence I have been looking for ways to stop grep for scanning the rest... (8 Replies)
Discussion started by: mpoblete
8 Replies

3. Shell Programming and Scripting

exact string match ; search and print match

I am trying to match a pattern exactly in a shell script. I have tried two methods awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath Both these methods require that I use the escape character. I am guessing that is why... (8 Replies)
Discussion started by: bash_in_my_head
8 Replies

4. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

5. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

6. Shell Programming and Scripting

Display match or no match and write a text file to a directory

The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget)... (4 Replies)
Discussion started by: cmccabe
4 Replies

7. Shell Programming and Scripting

Search from 1st match and end 2nd match

I've been looking through the forums for awhile now and looking at the man page for grep and egrep and not seeming to find this scenario so it might not be possible but figured I'd throw it out to get some ideas. I'm looking for a way to search a file for 1st match (example below net self) and... (3 Replies)
Discussion started by: djzah
3 Replies

8. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

9. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

10. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies
Mail::Message::Field::Address(3pm)			User Contributed Perl Documentation			Mail::Message::Field::Address(3pm)

NAME
Mail::Message::Field::Address - One e-mail address INHERITANCE
Mail::Message::Field::Address is a Mail::Identity is a User::Identity::Item SYNOPSIS
my $addr = Mail::Message::Field::Address->new(...); my $ui = User::Identity->new(...); my $addr = Mail::Message::Field::Address->coerce($ui); my $mi = Mail::Identity->new(...); my $addr = Mail::Message::Field::Address->coerce($mi); print $addr->address; print $addr->fullName; # possibly unicode! print $addr->domain; DESCRIPTION
Many header fields can contain e-mail addresses. Each e-mail address can be represented by an object of this class. These objects will handle interpretation and character set encoding and decoding for you. OVERLOADED
overload: boolean() The object used as boolean will always return "true" overload: string comparison() Two address objects are the same when their email addresses are the same. overload: stringification() When the object is used in string context, it will return the encoded representation of the e-mail address, just like string() does. METHODS
Constructors $obj->coerce(STRING|OBJECT, OPTIONS) Try to coerce the OBJECT into a "Mail::Message::Field::Address". In case of a STRING, it is interpreted as an email address. The OPTIONS are passed to the object creation, and overrule the values found in the OBJECT. The result may be "undef" or a newly created object. If the OBJECT is already of the correct type, it is returned unmodified. The OBJECT may currently be a Mail::Address, a Mail::Identity, or a User::Identity. In case of the latter, one of the user's addresses is chosen at random. Mail::Message::Field::Address->new([NAME], OPTIONS) See "Constructors" in Mail::Identity $obj->parse(STRING) Parse the string for an address. You never know whether one or more addresses are specified on a line (often applications are wrong), therefore, the STRING is first parsed for as many addresses as possible and then the one is taken at random. Attributes $obj->address() See "Attributes" in Mail::Identity $obj->charset() See "Attributes" in Mail::Identity $obj->comment([STRING]) See "Attributes" in Mail::Identity $obj->description() See "Attributes" in User::Identity::Item $obj->domain() See "Attributes" in Mail::Identity $obj->language() See "Attributes" in Mail::Identity $obj->location() See "Attributes" in Mail::Identity $obj->name([NEWNAME]) See "Attributes" in User::Identity::Item $obj->organization() See "Attributes" in Mail::Identity $obj->phrase() See "Attributes" in Mail::Identity $obj->username() See "Attributes" in Mail::Identity Collections $obj->add(COLLECTION, ROLE) See "Collections" in User::Identity::Item $obj->addCollection(OBJECT | ([TYPE], OPTIONS)) See "Collections" in User::Identity::Item $obj->collection(NAME) See "Collections" in User::Identity::Item $obj->find(COLLECTION, ROLE) See "Collections" in User::Identity::Item $obj->parent([PARENT]) See "Collections" in User::Identity::Item $obj->removeCollection(OBJECT|NAME) See "Collections" in User::Identity::Item $obj->type() Mail::Message::Field::Address->type() See "Collections" in User::Identity::Item $obj->user() See "Collections" in User::Identity::Item Accessors $obj->encoding() Character-set encoding, like 'q' and 'b', to be used when non-ascii characters are to be transmitted. Access to the content $obj->string() Returns an RFC compliant e-mail address, which will have character set encoding if needed. The objects are also overloaded to call this method in string context. example: print $address->string; print $address; # via overloading DIAGNOSTICS
Error: $object is not a collection. The first argument is an object, but not of a class which extends User::Identity::Collection. Error: Cannot coerce a $type into a Mail::Message::Field::Address When addresses are specified to be included in header fields, they may be coerced into Mail::Message::Field::Address objects first. What you specify is not accepted as address specification. This may be an internal error. Error: Cannot load collection module for $type ($class). Either the specified $type does not exist, or that module named $class returns compilation errors. If the type as specified in the warning is not the name of a package, you specified a nickname which was not defined. Maybe you forgot the 'require' the package which defines the nickname. Error: Creation of a collection via $class failed. The $class did compile, but it was not possible to create an object of that class using the options you specified. Error: Don't know what type of collection you want to add. If you add a collection, it must either by a collection object or a list of options which can be used to create a collection object. In the latter case, the type of collection must be specified. Warning: No collection $name The collection with $name does not exist and can not be created. SEE ALSO
This module is part of Mail-Box distribution version 2.105, built on May 07, 2012. Website: http://perl.overmeer.net/mailbox/ LICENSE
Copyrights 2001-2012 by [Mark Overmeer]. For other contributors see ChangeLog. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.14.2 2012-05-07 Mail::Message::Field::Address(3pm)
All times are GMT -4. The time now is 09:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy