![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 18911P12H9V16602Tp419Yp1375XPage Your help will be highly appreciated Last edited by rooh; 09-01-2003 at 09:32 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Yeah oombera is right and grep doesn't work
|
|
#6
|
||||
|
||||
|
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
|
||||
|
||||
|
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 |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|