Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Trimming in between the words

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-09-2013
navsan420's Unix or Linux Image
navsan420 navsan420 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 3 September 2015, 6:45 AM EDT
Posts: 34
Thanks: 4
Thanked 0 Times in 0 Posts
Trimming in between the words

Hi i have a log file
Code:
P12345_15728710[01/03/2013 18:16:35]:DEBUG:Begin 
P12345_15728710[01/03/2013 18:16:35]:DEBUG:Being  
P12345_15729310[01/03/2013 18:48:35]:DEBUG:GetAgen
P12345_15726510[01/03/2013 18:49:35]:DEBUG:end


i want to trim this file and i want like this
Code:
15728710[01/03/2013 18:16:35]
15728710[01/03/2013 18:16:35]
15729310[01/03/2013 18:48:35]
15726510[01/03/2013 18:49:35]

i tried sed ..but not working..


Code:
sed "s/.*P12345__ \(.*\) :DEBUG*/\1/"

Sponsored Links
    #2  
Old Unix and Linux 01-09-2013
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 11 December 2016, 8:34 AM EST
Location: Foxborough, MA
Posts: 7,989
Thanks: 195
Thanked 699 Times in 655 Posts

Code:
sed 's/.*_//;s/].*/]/' myFile

The Following User Says Thank You to vgersh99 For This Useful Post:
navsan420 (01-09-2013)
Sponsored Links
    #3  
Old Unix and Linux 01-09-2013
Jotne's Unix or Linux Image
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
Thanked 212 Times in 202 Posts

Code:
awk -F"_|:D" '{print $2}' infile

---------- Post updated at 14:02 ---------- Previous update was at 13:57 ----------


Code:
awk '{print substr($0,8,29)}' infile

    #4  
Old Unix and Linux 01-10-2013
navsan420's Unix or Linux Image
navsan420 navsan420 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 3 September 2015, 6:45 AM EDT
Posts: 34
Thanks: 4
Thanked 0 Times in 0 Posts
Also a small additional modifiaction ..in the below output



Code:
15728710[01/03/2013 18:16:35]
15728710[01/03/2013 18:16:35]
15728710[01/03/2013 18:48:35]
15729310[01/03/2013 18:48:35]
15729310[01/03/2013 18:48:35]
15729310[01/03/2013 18:48:35]
15729310[01/03/2013 18:50:35]
15726510[01/03/2013 18:49:35]
15726510[01/03/2013 18:49:35]
15726510[01/03/2013 18:49:35]
15726510[01/03/2013 18:50:35]
15726510[01/03/2013 18:53:35]

i want to select unique data with start and stop time stamp
i.e

Code:
15728710 [01/03/2013 18:16:35]-[01/03/2013 18:48:35]
15729310[01/03/2013 18:48:35]-[01/03/2013 18:50:35]
15726510[01/03/2013 18:49:35]-[01/03/2013 18:53:35]

---------- Post updated at 09:00 PM ---------- Previous update was at 12:36 AM ----------

please atleast provide some logic so that i can try...
Sponsored Links
    #5  
Old Unix and Linux 01-10-2013
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 11 December 2016, 7:22 AM EST
Location: Aachen, Germany
Posts: 9,955
Thanks: 201
Thanked 2,966 Times in 2,765 Posts
Try
Code:
$ awk -F[]_[]   '$2!=p {if (NR>1) printf "[%s]\n", d; printf "%s[%s]-", $2,$3;p=$2}
                 {d=$3}
                 END {printf "[%s]\n", d}
                ' file
15728710[01/03/2013 18:16:35]-[01/03/2013 18:48:35]
15729310[01/03/2013 18:48:35]-[01/03/2013 18:50:35]
15726510[01/03/2013 18:49:35]-[01/03/2013 18:53:35]


Last edited by RudiC; 01-10-2013 at 08:49 AM..
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trimming a string sukhdip Shell Programming and Scripting 2 01-31-2012 09:11 AM
Shell script to find out words, replace them and count words alex83 Shell Programming and Scripting 3 12-05-2010 05:18 PM
trimming sequences Xterra Shell Programming and Scripting 2 06-22-2010 08:26 PM
Trimming the spaces sharif UNIX for Advanced & Expert Users 3 07-07-2008 07:26 AM



All times are GMT -4. The time now is 09:45 AM.