The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to show it on separate line userking UNIX for Dummies Questions & Answers 2 07-23-2008 01:01 AM
Separate lines in a single '|' separated line hidnana Shell Programming and Scripting 3 03-17-2008 10:16 AM
unable to display the souce line in gdb gauri UNIX for Dummies Questions & Answers 4 04-19-2007 08:36 PM
Display a particular line from a file Rohini Vijay Shell Programming and Scripting 5 07-31-2006 07:27 AM
Listing words from a file on a Separate Line Astudent UNIX for Dummies Questions & Answers 2 03-14-2001 06:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-22-2008
suri.tyson suri.tyson is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 20
I would like to separate a line and display accordingly..

Hi all,

I have a log file which writes some information in it; now i've written a script to read particular line and print.. (shown below)

('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')

Am using print $7 where this writes the entire details which are in ( .... )

I would like to have only start date and end date from it..

Can anyone help me plz..
  #2 (permalink)  
Old 09-22-2008
palsevlohit_123 palsevlohit_123 is offline
Registered User
  
 

Join Date: Aug 2008
Location: India-Chennai
Posts: 120
Code:
$temp="('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')"
$echo "$temp"|tr '(' ' '|tr ')' ' '|awk -F"," '{print $1,$6}'
 
OUTPUT
 '20080920212141' '20080921064023'
  #3 (permalink)  
Old 09-22-2008
tpltp tpltp is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 30
Quote:
Originally Posted by palsevlohit_123 View Post
Code:
$temp="('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')"
$echo "$temp"|tr '(' ' '|tr ')' ' '|awk -F"," '{print $1,$6}'
 
OUTPUT
 '20080920212141' '20080921064023'
Hello Palsevlohit,

How to deal this with sed command?
When I try this, i got the following error:
Code:
echo "('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')" |sed -e 's/.*\(//' -e 's/\)*//'
Code:
sed: -e expression #1, char 8: Unmatched ( or \(

Last edited by tpltp; 09-22-2008 at 03:37 AM.. Reason: forgot to input the error message
  #4 (permalink)  
Old 09-22-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Quote:
Originally Posted by palsevlohit_123 View Post
[CODE]
$temp="('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')"
$echo "$temp"|tr '(' ' '|tr ')' ' '|awk -F"," '{print $1,$6}'
You don't need tr
Code:
echo $temp | awk -F'[(|,|)]' '{print $2, $7}'
  #5 (permalink)  
Old 09-25-2008
suri.tyson suri.tyson is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 20
Quote:
Originally Posted by palsevlohit_123 View Post
Code:
$temp="('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')"
$echo "$temp"|tr '(' ' '|tr ')' ' '|awk -F"," '{print $1,$6}'
 
OUTPUT
 '20080920212141' '20080921064023'

Hi.. thank you very much for all experts... :-)
It really helped me.. however i could not figure out the exact figure to get the output..
Acutally iam greping for a last line in some log file... (ex: grep insert).. which inturns search for the last line using tail -1 and updates the another log files with the entires...
The line exactly looks like is... (below)
new 1: insert into sapqd1.sdbah values ('20080725011009','net','QD1','DB','0','20080725052004','netbackup','netbackup')
This is a single line from which am trying to get the Start, End and the RC=0 from it.. Now when i use this tr command i dont know how many single cotts and brack's should be given.. (please help)
I am using the below script to write the particular line to a log file...
ssh -l ora${sid} ${primaryhost} "tail -50 /oracle/$ORACLE_SID/newbackup/END_BACKUP.log" |grep 'insert' |tail -1| awk '{print $7}' >> ${RESULTFILE}
which prints from open braket's $7 from the log file.. i.e ('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')..
Now if i want to read only the start and end time how do i write the tr command...
And also if possible can you please do me a favour to display the the same time in our own format (anything like below):
2008/09/20/ 21:21:41
Sat Sep 20 21:21:41
Any changes would be really appreciated..
thanking you in advance..
  #6 (permalink)  
Old 09-22-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Your sed script probably doesn't do what you want it to. The \( and \) should be in the same command because they are used for grouping. If you are trying to replace literal parentheses with nothing, take away the backslashes (and probably the .* and especially the erroneous last * after the closing parenthesis). Or better still, use tr -d '()' < file or the near-equivalent sed 's/[()]//g'
  #7 (permalink)  
Old 09-25-2008
suri.tyson suri.tyson is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 20
Hi.. thank you very much for all experts... :-)

It really helped me.. however i could not figure out the exact figure to get the output..

Acutally iam greping for a last line in some log file... (ex: grep insert).. which inturns search for the last line using tail -1 and updates the another log files with the entires...
The line exactly looks like is... (below)

new 1: insert into sapqd1.sdbah values ('20080725011009','net','QD1','DB','0','20080725052004','netbackup','netbackup')

This is a single line from which am trying to get the Start, End and the RC=0 from it.. Now when i use this tr command i dont know how many single cotts and brack's should be given.. (please help)

I am using the below script to write the particular line to a log file...

ssh -l ora${sid} ${primaryhost} "tail -50 /oracle/$ORACLE_SID/newbackup/END_BACKUP.log" |grep 'insert' |tail -1| awk '{print $7}' >> ${RESULTFILE}

which prints from open braket's $7 from the log file.. i.e ('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')..

Now if i want to read only the start and end time how do i write the tr command...

And also if possible can you please do me a favour to display the the same time in our own format (anything like below):

2008/09/20/ 21:21:41
Sat Sep 20 21:21:41

Any changes would be really appreciated..

thanking you in advance..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0