fixing with sed


 
Thread Tools Search this Thread
Operating Systems Linux fixing with sed
# 1  
Old 05-23-2008
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 01:09 PM.. Reason: added code tags
# 2  
Old 05-23-2008
Post some lines of the sql file and the desired output.

Regards
# 3  
Old 05-27-2008
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
# 4  
Old 05-27-2008
If I understand correctly what you try to do:

Code:
sed -r '/OPSDM002/! s/CREATE VIEW ([^ ]+)/CREATE VIEW OPSDM002.\1/' your_file

# 5  
Old 05-27-2008
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
# 6  
Old 05-27-2008
In that case, here we go with the backslash dance:
Code:
sed '/OPSDM002/! s/CREATE VIEW \([^ ]\+\)/CREATE VIEW OPSDM002.\1/'

# 7  
Old 05-27-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help fixing awk code

can someone please help me spot and fix the issue with the following code: awk -F, -v SEARCHPATT="(Wed|Tue)" -v ADDISTR="Mon|Tue|Wed|Thu|Fri|Sat|Sun" -vVF="$VALFOUND" "BEGIN{ {D = D = 1 D = D = 2 } $0 ~ "," VF "," {L = 1 ... (9 Replies)
Discussion started by: SkySmart
9 Replies

2. UNIX for Advanced & Expert Users

Help with fixing screen position

Hey guys, I am trying to make print a pattern with * on a 10*10 two dimensional array in a for loop and I want the incoming 10*10 to overlap the previous 10*10 so that the * look like it is moving. is there a way to fix the screen position? ever time it prints a 10*10 the screen moves. ... (3 Replies)
Discussion started by: amit14august
3 Replies

3. Shell Programming and Scripting

Fixing a shell script

I have this shell script that I wrote to check an input file to see if it is empty or not, and then clean the file from any line that starts with the sign "<" (without quotation marks" and then spell the number of line of the file, and the empty lines, too. The script then will create two output... (11 Replies)
Discussion started by: faizlo
11 Replies

4. AIX

Fixing security problem

Hi I use Rapid 7 to check some servers ( AIX 5.3 ) for security problems. There are 2 problems I don't know to deal with 1. Problem : TCP Sequence Number Approximation Vulnerability Solution : _Enable TCP MD5 Signature 2. Problem : HTTP Basic Authentication Enable Solution : _ Use... (5 Replies)
Discussion started by: bobochacha29
5 Replies

5. Homework & Coursework Questions

Help fixing my database script

1. The problem statement, all variables and given/known data: I need help I get a variant of syntax errors when compiling my script to maintain a database. It's a simple database meant to create/view/maintain vehicles. 2. Relevant commands, code, scripts, algorithms: my if statements have... (5 Replies)
Discussion started by: gamernerd101
5 Replies

6. Shell Programming and Scripting

help fixing awk statement

awk "BEGIN {if($MessageREAD<$ThresholdW) {print \"OK\" ; exit 0} else if(($MessageREAD>=$ThresholdW) && ($MessageREAD<$ThresholdC)) {print \"WARNING\" ; exit 1}" else if($MessageREAD<=$ThresholdC) {print \"CRITICAL\" ;... (4 Replies)
Discussion started by: SkySmart
4 Replies

7. Shell Programming and Scripting

Fixing the width of a word

Is there a way to fix the width of the word being printed to a file? I am trying to create an output to a file with columns , like a spread sheet. I have used "\t" to adjust the columns but still it does not show well in the file, mainly due to the variable length values in the column so \t does... (1 Reply)
Discussion started by: davidtd
1 Replies

8. Shell Programming and Scripting

Fixing corrupted vcard files.

KDE's Kontact PIM breaks quoted-printable vcard files because it linebreaks in the middle of a word. Take this text for example: NOTE;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=D7=A9=D7=95=D7=A8=D7=94 =D7=A 8=D7=90=D7=A9=D7=95=D7=A0=D7=94.\n=D7=94=D7=A9=D7=95=D7=A8=D7=94 =D7=94=D7= ... (7 Replies)
Discussion started by: dotancohen
7 Replies

9. Shell Programming and Scripting

Simple sed one-liner for fixing unencoded ampersands

Hi, I recieve some XML-files that constantly has bad encoded content. There are Ampersands that are not encoded correctly causing my XML-parser to halt. I wrote a sed one-liner to fix any stand alone "&": sed -e 's/&/&amp;/gi' input.xml testfile for input: <xml> <source> &quot; One &quot; </source>... (8 Replies)
Discussion started by: tobbe
8 Replies
Login or Register to Ask a Question