Grep and Print | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Grep and Print

UNIX for Dummies Questions & Answers


Tags
awk, grep

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-21-2013
Abhayman Abhayman is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 9 April 2013, 5:15 AM EDT
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
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  
Old 02-21-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 16 April 2014, 4:07 AM EDT
Location: India
Posts: 1,795
Thanks: 23
Thanked 515 Times in 494 Posts

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  
Old 02-21-2013
Abhayman Abhayman is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 9 April 2013, 5:15 AM EDT
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
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  
Old 02-21-2013
kg_gaurav kg_gaurav is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 22 March 2014, 5:52 AM EDT
Posts: 44
Thanks: 3
Thanked 2 Times in 2 Posts
Solution based on following assumption
  • all int have const length and all lines are in data.dat

Code:
for ln in `cat data.dat`
do
fin=`grep [0-9]{8} $ln`
lin=`grep[0-9]{4} $ln`
echo $fin----------$lin
done


Last edited by Scott; 02-21-2013 at 06:50 AM.. Reason: Code tags
Sponsored Links
    #5  
Old 02-21-2013
Abhayman Abhayman is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 9 April 2013, 5:15 AM EDT
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
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  
Old 02-21-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 16 April 2014, 4:07 AM EDT
Location: India
Posts: 1,795
Thanks: 23
Thanked 515 Times in 494 Posts

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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 12:11 PM.