|
|||||||
| 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
|
|||
|
|||
|
Grep and Print
Hi ,
I have data in below pattern 05:00:13,184 WARN [15501-24] ContentTransferService - CTS:createContent - File Name:470208627 Total time taken(ms):5137 05:00:13,184 WARN [15501-23] ContentTransferService - CTS:createContentWithFolderPath(uploadDocument) - File Name:[COLOR="rgb(139, 0, 0)"]295918481 [/COLOR]User Id:xyz Total time taken:5804 I want the output like 470208627 -- 5137 295918481 -- 5804 Can you please help me with it ? I tried few grep and awk but couldn't get it . |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
perl -lne '(/File Name:(\d+).*?time taken.*?:(\d+)/ || /File Name:.*?\](\d+).*?time taken:(\d+)/) && print "$1 -- $2"' file |
| The Following User Says Thank You to balajesuri For This Useful Post: | ||
Abhayman (02-21-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks for the reply. It works fine with the File Name as number but if the file name is alphanumberic then it doesnt work.These data get missing from the result. Code:
File Name:DLFE-300818427.pptx Total time taken(ms):3785 Last edited by Scott; 02-21-2013 at 06:49 AM.. Reason: Code tags |
|
#4
|
|||
|
|||
|
Solution based on following assumption
Code:
for ln in `cat data.dat`
do
fin=`grep [0-9]{8} $ln`
lin=`grep[0-9]{4} $ln`
echo $fin----------$lin
doneLast edited by Scott; 02-21-2013 at 06:50 AM.. Reason: Code tags |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Hi ,
The command works fine perl -lne '(/File Name \d+).*?time taken.*? \d+)/ || /File Name:.*?\](\d+).*?time taken \d+)/) && print "$1 -- $2"'But if the name is alphanumberic (DLFE-192818716.pptx) it doesnt work . I tried with /w option but that terminates the filename . |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Code:
perl -lne '(/File Name:([\w.-]+?) .*?time taken.*?:(\d+)/ || /File Name:.*?\]([\w.-]+?) .*?time taken:(\d+)/) && print "$1 -- $2"' file Hope the File Name doesn't have spaces in them :-) |
| Sponsored Links | ||
|
![]() |
| Tags |
| awk, grep |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Print lines before and after..not grep -A | zorrox | Shell Programming and Scripting | 9 | 04-20-2011 06:46 AM |
| Grep & print | gunaah | UNIX for Dummies Questions & Answers | 7 | 10-11-2008 03:47 PM |
| MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else | hariza | Shell Programming and Scripting | 4 | 09-18-2008 02:56 AM |
| Print lines after grep | jakSun8 | Shell Programming and Scripting | 4 | 06-25-2008 02:34 PM |
| using grep and print filename | ahjiefreak | Shell Programming and Scripting | 5 | 01-10-2008 10:47 AM |
|
|