Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Trimming in between the words

Shell Programming and Scripting


Closed Linux or Unix Question    
 
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: 1 June 2015, 1:48 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 offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 4 July 2015, 5:38 AM EDT
Location: Foxborough, MA
Posts: 7,825
Thanks: 174
Thanked 653 Times in 610 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 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 Unix and Linux 01-10-2013
navsan420's Unix or Linux Image
navsan420 navsan420 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 1 June 2015, 1:48 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 Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 3 July 2015, 9:53 AM EDT
Location: Aachen, Germany
Posts: 6,243
Thanks: 109
Thanked 1,700 Times in 1,592 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 Linux or Unix Question

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 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 06:09 AM.