The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Greping the required parameter... vijaya2006 Shell Programming and Scripting 3 04-01-2008 11:40 PM
need help in greping ali560045 Shell Programming and Scripting 4 02-12-2008 03:40 AM
greping with time stamp arunkumar_mca Shell Programming and Scripting 1 07-28-2006 01:20 AM
Greping certain lines csaha Shell Programming and Scripting 5 02-21-2006 12:43 AM
GREPing for Nulls Dr. DOT UNIX for Dummies Questions & Answers 4 09-17-2004 12:28 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-01-2003
Registered User
 

Join Date: Jul 2001
Posts: 62
Question Help with greping a field

Hi,

Suppose I have a file as below and I just want the field Invoice Number from this file , How can I do it.

/home/arbor>cat PH0034090202314800030IM-001


0Yp825XMilperra NSW 1891 189110H14V1Sp2871Yp300X Customer Service : 0000-368-81118H6.5V0Sp3130Yp50X For Australian GST purposes, when an amount of GST is expressed in a currency otherp3173Yp50X than AUD, this amount should be converted to AUS at the exchange rate publishedp3216Yp50X by the RBA at 4:00pm AEST on the same day as the date of this invoicep3302Yp50X Hanoi Australia Pty Ltdp3345Yp50X ABN: 00000000000p3388Yp50X 203 Military Road, St Leonards, Sydney NSW 2065
5H36V1Sp204Yp1734XInvoice12H9V0S0Bp419Yp50XAccount No:0P16.67H9.5V6Tp419Yp325XAUID132291P12H9V16602Tp505Yp50XName:0P16.67H9.5V6Tp505Yp325XSturdy Components Pty Ltdp548Yp325XATTN Mr g Kwohp591Yp325XP O Box 0035p634Yp325Xxxxxxx NSW 1891 18911P12H9V16602Tp419Yp1375XPage505Yp1375XInvoice Number:0P16.67H9.5V6Tp505Yp1750X13539391P12H9V16602Tp548Yp1375XInvoice Date:0P16.67H9.5V6Tp548Yp1750X08-Jan-011P12H9V16602Tp591Yp1375XBilling Period:0P16.67H9.5V6Tp591Yp1750X01-Dec-00 - 31-Dec-001P12H12V3B16602Tp892Yp969XInvoice p505Yp1375XInvoice Number:0P16.67H9.5V6Tp505Yp1750X13539391P12H9V16602Tp548Yp1375XInvoice Summary9Vp978Yp1023XRemittance Copy0Bp1021Yp759XPlease Return This Remittance With Payment To:0P16.67H9.5V6Tp1107Yp941XHanoi Australia Pty Ltdp1150Yp941XATTN: Accounts Receivablep1193Yp1067XGPO Box 5115p1236Yp1031XSydney NSW 2001p1279Yp1085XAustralia1P12H9V3B16602Tp1408Yp625XNew Charges(GST exclusive)0P16.67H9.5V0B6Tp1408Yp1570XAUD 197.551P12H9V3B16602Tp1451Yp625XNet Total Charges(GST exclusive)0P16.67H9.5V0B6Tp1451Yp1570XAUD 197.551P12H9V3B16602Tp1495Yp625XTaxes - GST @ 10.0 %0P16.67H9.5V0B6Tp1495Yp1588XAUD 19.761P12H9V3B16602Tp1538Yp625XTotal New Charges(GST inclusive)0P16.67H9.5V0B6Tp1538Yp1570XAUD 217.311P12H9V16602Tp1624Yp924XPayment Due Date 10-Feb-0118H6.5V3Bp3130Yp50X Invoice Number:0P16.67H9.5V6Tp505Yp1750X13539391P12H9V16602Tp548Yp1375X

Your help will be highly appreciated

Last edited by rooh; 09-01-2003 at 09:32 PM.
Forum Sponsor
  #2  
Old 09-02-2003
Registered User
 

Join Date: Aug 2003
Location: Dover, DE, USA
Posts: 31
If the invoice number is all on the same line and the format for Invoice Number is constant, then all I would do is:

/home/arbor> cat PH0034090202314800030IM-001 | grep Number:

or

/home/arbor> grep Number: PH0034090202314800030IM-001

Both of these should output only the lines containing Invoice Number:

If you want them outputted to a file, then use the > operator like so

/home/arbor> grep Number: PH0034090202314800030IM-001 > InvoiceNumbers.txt

Good luck
  #3  
Old 09-02-2003
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
To grab all the invoice numbers, the grep command won't work. Although it looks the file rooh posted contains many lines, all that text is actually only on three lines, with the invoice numbers only occuring on the last two...
  #4  
Old 09-02-2003
Registered User
 

Join Date: Aug 2003
Location: Dover, DE, USA
Posts: 31
oombera, as far as it only appearing as 3 lines, did you copy and post in to text editor and remove word wrap and saw 3 lines? If that is the case and it is indeed only 3 lines, then grep will not really be much assistance.

rooh, can you confirm whether oombera is correct about it being only 3 lines, or can you post the same output as a text file?
  #5  
Old 09-07-2003
Registered User
 

Join Date: Jul 2001
Posts: 62
Yeah oombera is right and grep doesn't work
  #6  
Old 09-08-2003
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
I'm not sure exactly how to help with this...

If you're sure the Invoice number will always be on the last line of the file and that there are no other colons (:) on the line, then you could use:

tail -1 text | awk -F":" '{print $2}'

If you're sure the last line will always be the same length, then you could use:

tail -1 text | awk '{print substr ($0, 280, 71)}'

From looking at your data, I don't think you could make either of these assumptions, but I'm not sure what else to suggest.
  #7  
Old 09-08-2003
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,493
egrep with regular expressions.

My thoughts are that you could do this with regular expressions.

egrep supports regular expressions (as does PERL, PHP, etc.)

Neo
Google The UNIX and Linux Forums
Closed Thread

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0