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

$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:

echo "('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')" |sed -e 's/.*\(//' -e 's/\)*//'
sed: -e expression #1, char 8: Unmatched ( or \(

[quote=palsevlohit_123;302238802]

$temp="('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')"
$echo "$temp"|tr '(' ' '|tr ')' ' '|awk -F"," '{print $1,$6}'

You don't need tr
echo $temp | awk -F'[(|,|)]' '{print $2, $7}'

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'

Hi.. thank you very much for all experts... :slight_smile:

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

Hi.. thank you very much for all experts... :slight_smile:
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..