Trimming in between the words | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Trimming in between the words

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-09-2013
navsan420's Avatar
navsan420 navsan420 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 26 September 2014, 7:39 AM EDT
Posts: 32
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 01-09-2013
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 26 October 2014, 12:57 AM EDT
Location: Foxborough, MA
Posts: 7,667
Thanks: 152
Thanked 586 Times in 551 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 01-09-2013
Jotne's Avatar
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 216 Times in 204 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 01-10-2013
navsan420's Avatar
navsan420 navsan420 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 26 September 2014, 7:39 AM EDT
Posts: 32
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 01-10-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 25 October 2014, 1:16 PM EDT
Location: Aachen, Germany
Posts: 4,427
Thanks: 73
Thanked 1,084 Times in 1,022 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 07:49 AM..
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
Trimming a string sukhdip Shell Programming and Scripting 2 01-31-2012 08:11 AM
Remove words by reading words from one file and deleting those words on other files. shoaibjameel123 Shell Programming and Scripting 2 08-25-2011 12:09 AM
Shell script to find out words, replace them and count words alex83 Shell Programming and Scripting 3 12-05-2010 04:18 PM
trimming sequences Xterra Shell Programming and Scripting 2 06-22-2010 07:26 PM
Trimming the spaces sharif UNIX for Advanced & Expert Users 3 07-07-2008 06:26 AM



All times are GMT -4. The time now is 02:00 AM.