The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem fixing e1000gx ni to 100fdx / Solaris 10 / T5220 moofoo SUN Solaris 6 01-14-2008 01:34 AM
fixing the error message when grep doesn't finds the pattern. silver123 UNIX for Dummies Questions & Answers 1 03-03-2006 02:59 AM
Fixing line length in a file dbessell UNIX for Advanced & Expert Users 2 08-04-2003 03:40 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-23-2008
Registered User
 

Join Date: May 2008
Location: St. Louis
Posts: 74
fixing with sed

I am trying to replace the value of $f3 but its not working . I don't know what I am missing here .

Code:
 cat dim_copy.20080516.sql | grep -i "create view" | grep -v OPSDM002 |  while read f1 f2 f3 f4 f5 f6 f7 f8 f9   
       do
              echo " $f3 " 
             sed -e s/"${f3}"/OPSDM002."${f3}"/ dim_copy.20080516.sql > dim_copy.20080516.sql1
         done
Can someone suggest me how to fix it .

Thanks in advance

Last edited by Yogesh Sawant; 05-23-2008 at 09:09 AM. Reason: added code tags
Reply With Quote
Forum Sponsor
  #2  
Old 05-23-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,332
Post some lines of the sql file and the desired output.

Regards
Reply With Quote
  #3  
Old 05-27-2008
Registered User
 

Join Date: May 2008
Location: St. Louis
Posts: 74
The SQL file is

CREATE VIEW MOUSE_UHC AS SELECT DT_SYS_ID ,DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR
FROM OPSDM002.DIM_COPY;
CREATE VIEW OPSDM002.TABLE_UHC AS SELECT DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR,LOAD_DT,WEEK_NBR_YR,SEQ_NBR
FROM OPSDM002.DIM_COPY;
CREATE VIEW RAT_UHC AS SELECT DT_SYS_ID ,DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR


The desired output is

CREATE VIEW OPSDM002.MOUSE_UHC AS SELECT DT_SYS_ID ,DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR
FROM OPSDM002.DIM_COPY;
CREATE VIEW OPSDM002.TABLE_UHC AS SELECT DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR,LOAD_DT,WEEK_NBR_YR,SEQ_NBR
FROM OPSDM002.DIM_COPY;
CREATE VIEW OPSDM002.RAT_UHC AS SELECT DT_SYS_ID ,DAY_ABBR_CD,LST_DAY_MO_IND,MONTH_NBR,FULL_DT,DAY_NBR



Thanks
Reply With Quote
  #4  
Old 05-27-2008
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
If I understand correctly what you try to do:

Code:
sed -r '/OPSDM002/! s/CREATE VIEW ([^ ]+)/CREATE VIEW OPSDM002.\1/' your_file
Reply With Quote
  #5  
Old 05-27-2008
Registered User
 

Join Date: May 2008
Location: St. Louis
Posts: 74
Ripat ,
When I run your command i get the following error

#sed -r '/OPSDM002/! s/CREATE VIEW ([^ ]+)/CREATE VIEW OPSDM002.\1/' dim_copy.20080516.sql
sed: illegal option -- r
Usage: sed [-n] Script [File ...]
sed [-n] [-e Script] ... [-f Script_file] ... [File ...]


Thanks
Reply With Quote
  #6  
Old 05-27-2008
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
In that case, here we go with the backslash dance:
Code:
sed '/OPSDM002/! s/CREATE VIEW \([^ ]\+\)/CREATE VIEW OPSDM002.\1/'
Reply With Quote
  #7  
Old 05-27-2008
Registered User
 

Join Date: May 2008
Location: St. Louis
Posts: 74
Ripat ,
This is not working too.

#sed '/OPSDM002/! s/CREATE VIEW \([^ ]\+\)/CREATE VIEW OPSDM002.\1/' dim_copy.20080516.sql
sed: /OPSDM002/! s/CREATE VIEW \([^ ]\+\)/CREATE VIEW OPSDM002.\1/ is not a recognized function.


Thanks
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0