|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
How to print first occurence
Hi there, how can i print the first pattern occurrence in a .log file? I want to print the filename of the first 17262? I tried but all I can do is print all the lines with the number 17262? I tried using awk and sed but nothing! I just want filename! Here´s an example: Code:
17259 1349258032 773472 PS Some text 17262 1349258032 773735 CE Some text 17267 1349258052 351658 CS tests/filename Some text 17267 1349258052 352041 QS Some text 17259 1349258052 352109 QR Some text 17259 1349258052 352432 PS Some text 17267 1349258052 375328 CE Some text Can someone help me! Thanks!
|
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
I assume that you meant
17267 instead of
17262 . Code:
awk '/^17267/{sub(/.*\//,"",$5);print $5;exit(0)}' fileLast edited by elixir_sinari; 10-12-2012 at 10:07 AM.. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks but with Code:
awk '/^17267/{sub(/.*\//,"",$5);print $5;exit(0)}' filei have no answer from terminal. Can you explain your solution? Thanks! Last edited by jim mcnamara; 10-13-2012 at 12:32 AM.. |
|
#4
|
|||
|
|||
|
Or Code:
awk -F/ '/^17267/{split($NF,a," ");print a[1];exit(0)}' file |
| Sponsored Links | ||
|
![]() |
| Tags |
| first occurrence |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Number each occurence using sed | xerox | Shell Programming and Scripting | 5 | 01-17-2012 06:43 AM |
| print lines between two strings but for the first occurence. solved | Sangal_ak04 | Shell Programming and Scripting | 0 | 04-26-2010 05:40 PM |
| Replacing nth occurence | raghav288 | Shell Programming and Scripting | 11 | 10-29-2009 11:39 AM |
| Print row if value in column 1 is the first occurence | Raynon | Shell Programming and Scripting | 7 | 03-18-2008 02:31 AM |
| First Occurence | kkm_job | UNIX for Advanced & Expert Users | 5 | 10-30-2006 05:37 PM |
|
|