sed to fix view names


 
Thread Tools Search this Thread
Operating Systems Linux sed to fix view names
# 1  
Old 05-14-2008
sed to fix view names

I have a ddl file which have lots of view in it. I want to replace all the existing views with VW_< view name> . I am prefixing VW to existing view name .

For example, In old file grep on view is like this

CREATE VIEW OPSDM001.PROVIDER_MBR_PRI ( MBR_PRI_PROV_SYS_ID, MBR_PRI_COS_PROV_SPCL_CD,
CREATE VIEW OPSDM001.PROVIDER_REF ( REF_PROV_SYS_ID, REF_COS_PROV_SPCL_CD,
CREATE VIEW OPSDM001.PROVIDER_SRVC ( SRVC_PROV_SYS_ID, SRVC_COS_PROV_SPCL_CD,


but after editing , I want the result like this

CREATE VIEW OPSDM001.VW_PROVIDER_MBR_PRI ( MBR_PRI_PROV_SYS_ID, MBR_PRI_COS_PROV_SPCL_CD,
CREATE VIEW OPSDM001.VW_PROVIDER_REF ( REF_PROV_SYS_ID, REF_COS_PROV_SPCL_CD,
CREATE VIEW OPSDM001.VW_PROVIDER_SRVC ( SRVC_PROV_SYS_ID, SRVC_COS_PROV_SPCL_CD,

It could take care of any number of view occurance .
Any help is appreciated ,
Thanks in advance ,
# 2  
Old 05-14-2008
Something like this should do the job:

Code:
sed 's/\(.*\.\)\(.*\)/\1VW_\2/' file > newfile

Regards
# 3  
Old 05-14-2008
Thanks Frankiln but its making VW_ changes to all the table names too in the file. I need VW_ only for view names.

If my original file is like this ,

create table opsdm001.dim_date
create view opsdm001.dim_date_view

then i want to change it to

create table opsdm001.dim_date
create view opsdm001.VW_dim_date_view

but with your suggestion, the table name is also prefixed with VW_

Thanks again ,
# 4  
Old 05-14-2008
Try this:

Code:
sed '/^create view/s/\(.*\.\)\(.*\)/\1VW_\2/' file > newfile

Regards
# 5  
Old 05-14-2008
Sorry Franklin, that didn't work at all .
# 6  
Old 05-14-2008
Franklin,
My bad ! You were right. It worked. I was doing change for create view as lower case while in my file its all uppercase .

Thanks a lot !!!

Daya
# 7  
Old 05-15-2008
thread closed

Last edited by capri_drm; 05-16-2008 at 12:52 AM.. Reason: new thread
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Moving from Desktop View to Mobile View

See attached video for a demo on how to move back and forth from the desktop view to the mobile view. Currently this only works for the home page, but I will work on some new PHP code in the future to make this work with the page we are currently on. Edit: The issue with making every page ... (2 Replies)
Discussion started by: Neo
2 Replies

2. UNIX for Beginners Questions & Answers

sed awk: split a large file to unique file names

Dear Users, Appreciate your help if you could help me with splitting a large file > 1 million lines with sed or awk. below is the text in the file input file.txt scaffold1 928 929 C/T + scaffold1 942 943 G/C + scaffold1 959 960 C/T +... (6 Replies)
Discussion started by: kapr0001
6 Replies

3. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

4. Shell Programming and Scripting

making find/sed to include directory names with spaces

how can i make find/sed to include directory names with spaces the command is like this for i in `find wp-content/themes -type f -print0 | xargs -0 grep -l -iE 'e'`;do sed -i -e 's/word1/word2/gI' "$i";done but it skips one directory names with spaces sed: can't read ./Nova: No such... (5 Replies)
Discussion started by: vanessafan99
5 Replies

5. UNIX for Dummies Questions & Answers

Using SED to fix base64_decode attack/hack

last night our server was hit with an attack that infected every php file on the server and inserted the following code /*god_mode_on*/eval(base64_decode with a ton of other characters after. As it infected every php file i have been trying to clean it using a sed command to go through... (2 Replies)
Discussion started by: derrickyoung95
2 Replies

6. Shell Programming and Scripting

Fix timestamp with Sed or Awk

Hi I am dealing with the following string: Date: Thur, 13 March 2011 01:01:10 +0000 I asked for help in another topic that converted a similar string: Date: Thur, 13 March 2011 9:50 AM To a 24 hr standard. The problem is that it comes out as: Date: Thur, 13 March 2011 9:50:00 +0000... (4 Replies)
Discussion started by: duonut
4 Replies

7. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

8. Shell Programming and Scripting

SED - editing file names (End of line problem?)

For lists in sed, to say what to replace, is this correct: I am hoping that this would recognise that either a "." is present, or that the substitution happens at the end of the line. For files with extensions , my script works perfectly. My problem is, files without extentions, i.e. . ... (1 Reply)
Discussion started by: busillis
1 Replies

9. Shell Programming and Scripting

CamelCasify file names (sed?)

Dear forum, I need to rename a bunch of files according to their first line, in CamelCase. I am having problems with the conversion from "normal string title" or "NST syndrome" to, respectively, "NormalString" or "NSTSyndrome". First character of a word to uppercase and drop spaces. I was... (1 Reply)
Discussion started by: vlf
1 Replies

10. OS X (Apple)

changing multiple directory names w/ sed

ive looked and couldnt find an answer... can someone tell me how i can replace spaces and characters with an "_" on multiple folders? thanx muchly. (1 Reply)
Discussion started by: RahJiggah
1 Replies
Login or Register to Ask a Question