Question to gurus about sed.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question to gurus about sed.
# 1  
Old 07-17-2013
Question to gurus about sed.

Hi Folks.
I need change something into file and after all manipulation I need delete only last COMMA into this piece of code ->
Code:
  GROUP 1 (
    '/oralog1/ORAPRD/log01a.dbf',
    '/oralog2/ORAPRD/log01b.dbf'
  ) SIZE 512M,
  GROUP 2 (
    '/oralog1/ORAPRD/log02a.dbf',
    '/oralog2/ORAPRD/log02b.dbf'
  ) SIZE 512M,
  GROUP 3 (
    '/oralog1/ORAPRD/log03a.dbf',
    '/oralog2/ORAPRD/log03b.dbf'
  ) SIZE 512M,
DATAFILE

Final view of this code need to
Code:
  GROUP 1 (
    '/oralog1/ORAPRD/log01a.dbf',
    '/oralog2/ORAPRD/log01b.dbf'
  ) SIZE 512M,
  GROUP 2 (
    '/oralog1/ORAPRD/log02a.dbf',
    '/oralog2/ORAPRD/log02b.dbf'
  ) SIZE 512M,
  GROUP 3 (
    '/oralog1/ORAPRD/log03a.dbf',
    '/oralog2/ORAPRD/log03b.dbf'
  ) SIZE 512M
DATAFILE

--> Please pay attention,that we have not comma after SIZE 512M into GROUP 3 section.


Thanks for all tips and answers.

Stas.

Last edited by Scott; 07-17-2013 at 05:46 AM.. Reason: Code tags, please
# 2  
Old 07-17-2013
if your file is small the make use of tac..
here in sed dot use g option doing that u will replace only first occurance and since we are using tac it would be last occurance
Code:
 
tac filename|sed -e '0,/,/{s/,//}'|tac


Last edited by vidyadhar85; 07-17-2013 at 05:30 AM..
# 3  
Old 07-17-2013
Hi.,
Thanks for you answer, but I paste only piece of code.
File indeed not large, but this delete comma not in proper place.

I need delete it only at section of ) SIZE 512M, before DATAFILE word.


Thanks again and wait for answers, Stas
# 4  
Old 07-17-2013
Please post the exact data from which it has to be removed and when u say its not working please say whay and what is not working..

how about this? (its same as sed)

Code:
 
tac filename|awk '/,/ && ! seen {sub(",","");seen=1} {print}' | tac

# 5  
Old 07-17-2013
Hi
According to You advice I reversing order file and as you explain first occurance would be last occurance. This work correct.
My file is ->
Code:
STARTUP NOMOUNT
CREATE CONTROLFILE SET DATABASE "ORAPRD" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 315
    MAXLOGMEMBERS 2
    MAXDATAFILES 500
    MAXINSTANCES 63
    MAXLOGHISTORY 29040
LOGFILE
  GROUP 1 (
    '/oralog1/ORAPRD/log01a.dbf',
    '/oralog2/ORAPRD/log01b.dbf'
  ) SIZE 512M,
  GROUP 2 (
    '/oralog1/ORAPRD/log02a.dbf',
    '/oralog2/ORAPRD/log02b.dbf'
  ) SIZE 512M,
  GROUP 3 (
    '/oralog1/ORAPRD/log03a.dbf',
    '/oralog2/ORAPRD/log03b.dbf'
  ) SIZE 512M,
DATAFILE
  '/oradata2/ORAPRD/system01.dbf',
  '/oradata2/ORAPRD/system02.dbf',
  '/oradata2/ORAPRD/undo01.dbf',
  '/oradata2/ORAPRD/APPS_TS_ARCHIVE01.dbf',
  '/oradata2/ORAPRD/APPS_TS_INTERFACE01.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA01.dbf',
  '/oradata2/ORAPRD/APPS_TS_NOLOGGING01.dbf',
  '/oradata2/ORAPRD/APPS_TS_QUEUES01.dbf',
  '/oradata2/ORAPRD/APPS_TS_SEED01.dbf',
  '/oradata2/ORAPRD/APPS_TS_SEED02.dbf',
  '/oradata2/ORAPRD/APPS_TS_SUMMARY01.dbf',
  '/oradata1/ORAPRD/APPS_TS_TX_DATA01.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA02.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA03.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX01.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX02.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX03.dbf',
  '/oradata2/ORAPRD/ctxd01.dbf',
  '/oradata2/ORAPRD/disco.dbf',
  '/oradata2/ORAPRD/ild.dbf',
  '/oradata2/ORAPRD/interim.dbf',
  '/oradata2/ORAPRD/nice_data01.dbf',
  '/oradata2/ORAPRD/nice_idx01.dbf',
  '/oradata2/ORAPRD/perf.dbf',
  '/oradata2/ORAPRD/sncash.dbf',
  '/oradata2/ORAPRD/owapub.dbf',
  '/oradata2/ORAPRD/sysaux01.dbf',
  '/oradata2/ORAPRD/undo02.dbf',
  '/oradata2/ORAPRD/undo03.dbf',
  '/oradata2/ORAPRD/APPS_TS_TOOLS01.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA04.dbf',
  '/oradata2/ORAPRD/APPS_TS_SUMMARY02.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA02.dbf',
  '/oradata1/ORAPRD/APPS_TS_TX_DATA05.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA03.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX04.dbf',
  '/oradata2/ORAPRD/APPS_TS_QUEUES02.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA04.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA06.dbf',
  '/oradata2/ORAPRD/undo04.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA05.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA06.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA07.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA07.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA08.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA09.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA10.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA11.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA08.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA12.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX05.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA13.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA14.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA09.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA15.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA16.dbf',
  '/oradata2/ORAPRD/sysaux02.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA17.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA10.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA18.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA19.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX06.dbf',
  '/oradata2/ORAPRD/nice_data02.dbf',
  '/oradata2/ORAPRD/APPS_TS_INTERFACE02.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA20.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA21.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA22.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA23.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA11.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA24.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA25.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA26.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA27.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA28.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA29.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA12.dbf',
  '/oradata2/ORAPRD/rpro_apex01.dbf',
  '/oradata2/ORAPRD/rpro_apex_files01.dbf',
  '/oradata2/ORAPRD/revpro_01.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA30.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX07.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA31.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA32.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA33.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA34.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA35.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_DATA13.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA36.dbf',
  '/oradata2/ORAPRD/nice_data03.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA37.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX08.dbf',
  '/oradata2/ORAPRD/APPS_TS_MEDIA38.dbf',
  '/oradata2/ORAPRD/APPS_TS_TX_IDX09.dbf'
CHARACTER SET IW8ISO8859P8
;

Thanks Stas

Last edited by Scott; 07-17-2013 at 09:29 AM.. Reason: Use code tags, please...
# 6  
Old 07-17-2013
If this is your file your requirement is not right at all. You have to go for pattern matching and you have to decide which pattern to go for.
# 7  
Old 07-17-2013
Code:
cat file | perl -nle 's/SIZE 512M,\nDATAFILE/SIZE 512M\nDATAFILE/m;print'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question to gurus with expect

Hi., I need to ask question for expect script. I have prompt like # and very long script (orachk). I added to expect script line set prompt "(%|#|\\\$) $" and insert into it also piece of code ---- expect { timeout { puts "Running..." exp_continue } ... (0 Replies)
Discussion started by: beckss
0 Replies

2. UNIX for Dummies Questions & Answers

Calling all the awk gurus out there.

Hi all, I just signed up to the forums, although, I have lurked on here for awhile. Anyways, my issue is I am trying to get awk to spit out something I can use without having to spend hours in excel hell haha. So, I used sed to replace the spaces with semicolons and redirected that to a file. ... (6 Replies)
Discussion started by: savigabi
6 Replies

3. Shell Programming and Scripting

calling mysql gurus : need help with my view

hi there I have a view which is working fine, but i have been told that i need to make sure the resulting output excludes all rows with nic_status equal to the string "removed". Does anybody know in which part of the code below i would place the conditional ... WHERE nic_status !=... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

4. Shell Programming and Scripting

Bash script questions for gurus

guys, I need a steer in the right direction for this issue. it would be great if anyone of you can help me out. i have a textfile where i want to swap the lines based on the user input. The textfile is looks like the #file 1 name TB #file 1 ID 1000 # #file for ID1 system1... (3 Replies)
Discussion started by: mayi
3 Replies

5. Shell Programming and Scripting

VI Editor - question for unix gurus !!

I have created a dummy file -demo.txt On my machine-A (oslevel-5300-08) I can display the file content in HEX format through VI editor using :%!xxd but on other machine-B (oslevel - 5300-06) , I get error as "sh: xxd: not found." machine-A: $ cat demo.txt Hello World ! I can display... (7 Replies)
Discussion started by: Rahulpict
7 Replies

6. Shell Programming and Scripting

Unix/Linux gurus...here is Q 4u

Suppose I have two files 1.txt and 2.txt. My aim is to find (Total execution time/Number of executions) then sort the result as in decreasing order. Can anyone provide me any shell/perl/awk script or a Command to do that in faster way ? 1.txt : =============================== Number of... (4 Replies)
Discussion started by: Rahulpict
4 Replies

7. Shell Programming and Scripting

Hey Perl Gurus

Hey guys im trying to get this if statement to work and i dont know whats wrong. can anybody help? if($author=~/\A+\Z/i)&&(length($author!=0)) { print " $author validation correct" } elsif($author!=~/\A+\Z/i)&&(length($author=0)) { $author='BLANK'; } else { ... (1 Reply)
Discussion started by: neil1983
1 Replies

8. Shell Programming and Scripting

SED GURUS - Help!

I wish to substituite a string on each line but ONLY if it appears within double-quotes: this_string="abc#def#geh" # Comment here I wish to change the "#" characters within the double quoted string to "_": this_string="abc_def_geh" # Comment here ... but as you see, the "comment" hash... (2 Replies)
Discussion started by: Simerian
2 Replies

9. UNIX for Advanced & Expert Users

Any RF unix gurus out there?

I am having a problem here. We are having several problems in regards to hung process's on unix (HPUX box), caused by my RF equipment (Mobile data capture units). these contact the host via a simply telnet session and locks the system? Is it a timeout problem as the timeout is disabled on the host. (5 Replies)
Discussion started by: Subrosa
5 Replies
Login or Register to Ask a Question