I would like to separate a line and display accordingly..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I would like to separate a line and display accordingly..
# 1  
Old 09-22-2008
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  
Old 09-22-2008
Code:
$temp="('20080920212141','net','Q05','DB','0','20080921064023','netbackup','netbackup')"
$echo "$temp"|tr '(' ' '|tr ')' ' '|awk -F"," '{print $1,$6}'
 
OUTPUT
 '20080920212141' '20080921064023'

# 3  
Old 09-22-2008
Quote:
Originally Posted by palsevlohit_123
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 04:37 AM.. Reason: forgot to input the error message
# 4  
Old 09-22-2008
Quote:
Originally Posted by palsevlohit_123
[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  
Old 09-22-2008
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'
# 6  
Old 09-25-2008
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..
# 7  
Old 09-25-2008
Quote:
Originally Posted by palsevlohit_123
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..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

2. Shell Programming and Scripting

[Solved] How to separate one line to mutiple line based on certain number of characters?

hi Gurus, I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example: abcdefghi high abaddffdd I want to separate the line to multiple lines for every 4 charactors. the result should be abcd efgh i hi gh a badd ffdd Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies

3. Shell Programming and Scripting

How to separate one line to mutiple line based on one char?

Hi Gurus, I need separate one file which is one huge line to mutiple line. file like abcd # bcd # def # fge # ged I want to get abcd bcd def fge ged Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

4. Shell Programming and Scripting

Read each line and saving the line in separate files

Hi Experts, I am having a requirement like this; Input file EIM_ACCT.ifb|1001|1005 EIM_ADDR.ifb|1002|1004 EIM_ABD.ifb|1009|1007 I want to read each line of this file and pass each line,one at a time,as an argument to another script. eg; 1.read first line->store it to a file->call... (2 Replies)
Discussion started by: ashishpanchal85
2 Replies

5. Shell Programming and Scripting

[Solved] making each word of a line to a separate line

Hi, I have a line which has n number of words with separated by space. I wanted to make each word as a separate line. for example, i have a file that has line like i am a good boy i want the output like, i am a good (8 Replies)
Discussion started by: rbalaj16
8 Replies

6. Shell Programming and Scripting

How to separate a line with or without using newline command?

Hi, I am using Putty for unix shell scripting. I need some suggestions in splitting the 'output line' into two separate lines. Originally I am getting the input from another text file A. And when looking at the content in the text file A, the lines are separated in the way I want. After that I... (10 Replies)
Discussion started by: snr100
10 Replies

7. Shell Programming and Scripting

Replace a line with a separate line in code

I have a bunch of files that are like this: <htmlstuffs>HTML STUFFS</endhtmlstuffs> <h1>Header</h1> <htmlstuffs>HTML STUFFS</endhtmlstuffs> <h1>Unique</h1> <html stuffs>HTML STUFFS</endhtmlstuffs> And Here's what I'd like it to look like: <htmlstuffs>HTML STUFFS</endhtmlstuffs>... (2 Replies)
Discussion started by: kason
2 Replies

8. Shell Programming and Scripting

line separate (pls)

Hello everybody I made code to move some files to another place for example(I moved MM file TO BIN folder ) and the MM path I put it in different file e.g(0:HOME/unixstuff/MM) so my question is who I can separate the path line and use the number 0: and MM as parameter because if I want to... (2 Replies)
Discussion started by: falm
2 Replies

9. Shell Programming and Scripting

separate a line having particular field

hi i have a file containes data like, 20081013-030618.675199 D 17 Change state DATA_RECEIVE->EOD, RC=0 20081013-030618.868358 D 17 Reading data... 20081013-030618.868498 D 18 Received 5 bytes 20081013-030618.868537 U Buffer received: now i need to cut the 4th field i.e 17 and write... (2 Replies)
Discussion started by: Satyak
2 Replies

10. UNIX for Dummies Questions & Answers

how to show it on separate line

# echo $PATH /home/user01/bin:/usr/local/bin:/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/dist/perl5/bin:/dist/fsf/bin:.:/usr/dt/bin:/etc/dt/tbin:/usr/openwin/bin how to show the PATH in separate line, ie: /home/user01/bin /usr/local/bin /usr/bin:/bin /usr/ccs/bin /usr/ucb etc...... (2 Replies)
Discussion started by: userking
2 Replies
Login or Register to Ask a Question