selective replacing text using sed/perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting selective replacing text using sed/perl
# 1  
Old 09-11-2009
selective replacing text using sed/perl

Hi,

I have the following text which I want to search and replace using perl and sed. I would appreciate any help.
Please notice the file contains schema name with a single dot and a double dot . &&WEBDIR_SCHEMA. and &&WEBDIR_SCHEMA .. }

I would like to change it to the acutal schema name.tablename
The schema name in this case will be DSP


Before

SELECT COUNT(*) INTO CTR FROM &&WEBDIR_SCHEMA.SYSPROP WHERE DOMAIN = 'test' AND PNAME = 'svcURL';

SELECT COUNT(*) INTO CTR FROM &&WEBDIR_SCHEMA..SYSPROP
WHERE DOMAIN = 'test' AND PNAME = 'MaxConnectionsHost';


After
SELECT COUNT(*) INTO CTR FROM DSP.SYSPROP WHERE DOMAIN = 'test' AND PNAME = 'svcURL';

SELECT COUNT(*) INTO CTR FROM DSP.SYSPROP
WHERE DOMAIN = 'test' AND PNAME = 'MaxConnectionsHost';



Thanks,

Last edited by jville; 09-15-2009 at 11:33 AM..
# 2  
Old 09-11-2009
In sed.,
Code:
sed 's/&&WEBDIR_SCHEMA\.\{1,2\}/DSP./' FILENAME

In Perl.,
Code:
perl -e 'while(<>){ s/&&WEBDIR_SCHEMA\.{1,2}/DSP./;print }' FILENAME

# 3  
Old 09-11-2009
How can do in the following way ?

#!/bin/bash
USER=DSP
for line in `ls test_001.sql`
do
perl -pi -e 's/&&WEBDIR_SCHEMA\.{1,2}/${USER}./g' ${line}
done

---------- Post updated at 10:27 AM ---------- Previous update was at 07:39 AM ----------

Thank-you Geek, I figured out a way to use your suggestion and modify it necessary to my needs.
Thanks for jumpstarting me ! I really appreciate.
# 4  
Old 09-12-2009
I am very eager to know,

1. What is the solution you found ( you wanted ) ?
2. What modifications.. and the path in learning ( what ever possible to explain ).
# 5  
Old 09-12-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.
  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

@jville
please edit your posts and add code tags.

Thanks,
# 6  
Old 09-15-2009
done ! thanks.

---------- Post updated at 06:45 AM ---------- Previous update was at 06:34 AM ----------

Geek ,
Please notice the single quotes in the sed commad for ${USER}

I took the liberty to change the perl command you had provided.

Code:
perl -e 'while(<>){ s/&&WEBDIR_SCHEMA\.{1,2}/DSP./;print }' FILENAME




Code:
#!/bin/bash
USER=DSP
for line in `ls test_001.sql`
do
perl -pi -e 's/&&WEBDIR_SCHEMA\.{1,2}/'${USER}.'/g' ${line}
done


Last edited by vgersh99; 09-15-2009 at 11:56 AM.. Reason: code tags, PLEASE!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Query on using command "sed" for replacing text in bash shell

Re: Query on using command "SED" for replacing text in bash shell While using the command "sed" for find and replace, I wanted to know how one could find a constant and replace it with a variable inside the quotation syntax of sed? I wanted to replace constant 3 with variable name... (3 Replies)
Discussion started by: achandra81
3 Replies

2. Shell Programming and Scripting

Replacing values into a single column. sed/PERL

Hello everyone, i need to replace in the second column of my csv file, points by nothing and dash by comma like this: Input: 1 2 1;12.111.312-2;1.2;2;1-3 2 1 1;11.212.331-1;3.3;1;2-2 Output: 1 2 1;12111312;2;1.2;2;1-3 2 1 1;11212331;1;3.3;1;2-2 SED or PERL commands preferably. ... (7 Replies)
Discussion started by: satir
7 Replies

3. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

4. Shell Programming and Scripting

Replacing text in Perl given by command line

Hi I need to write a Perl script that the file given as first argument of the command line that will find all occurrences of the string given as the third argument of the command line and replace with the string given as the fourth argument. Name newfound file is specified as the second... (3 Replies)
Discussion started by: nekoj
3 Replies

5. Shell Programming and Scripting

Perl: selective printing of lines

Hi, I have a file with lines like this. 2 7 18 ggcgt anna 2 7 18 hhchc sam 3 7 18 hhdjcc ross 4 7 18 hhcjd jenny 0 8 21 jjdhs sam 3 8 21 kkok bush 2 9 24 kosss BrenhamIf the values of the second column are equal, print only those lines with the least first column value. So in... (5 Replies)
Discussion started by: polsum
5 Replies

6. Shell Programming and Scripting

sed selective printing

Hi, I have an xml file having serveral smiliar lines as below <INPUT VAR1 ="" DATATYPE ="number(p,s)" VAR2 ="" VAR3 ="3" VAR4="0" VAR5 ="ELEMITEM" VAR6 ="NO" VAR7 ="NOT A KEY" VAR8 ="17" LEVEL ="0" NAME ="UNIX" NULLABLE ="NOTNULL" OCCURS ="0" OFFSET ="19" PHYSICALLENGTH ="15"... (3 Replies)
Discussion started by: dips_ag
3 Replies

7. Shell Programming and Scripting

Replacing text in a .csv file using Perl

I have played with this for some time but i dont seem like i am getting it right. I am trying to change the delimiters on a file so i can import it into a database. this file has rows of data separated by enter Right now the delimiters are represented by tabs and " ". e.g. "dlfkldfs... (9 Replies)
Discussion started by: salemh
9 Replies

8. Shell Programming and Scripting

sed: Replacing two lines of text

I just created a file in vi, looks like this: Hello nobody nobody What I need is to have sed change the file so it looks like this: Hello everybody In other words, the sed query needs to look for both instances of "nobody" before it puts the word "everybody" on the first line. ... (2 Replies)
Discussion started by: calrog
2 Replies

9. Shell Programming and Scripting

Simple 'sed' script for replacing text

Hi All, So I found a simple sed command to replace text in a file (http://www.labnol.org/internet/design/wordpress-unix-replace-text-multiple-files/1128/): sed -e 's/OLDtext/NEWtext/' -i file(s) Because I'm lazy and don't want to remember this each time I want to do this, I wrote the following... (4 Replies)
Discussion started by: ScKaSx
4 Replies

10. Shell Programming and Scripting

clip selective text and minus

After doing some scripting in a log file, I am left with some lines like this. 10:00:00 Received Message Message ID 1 10:05:00 Published Message Message ID 1 10:10:00 Received Message Message ID 2 10:15:00 Published Message Message ID 2 10:20:00 Received Message Message ID 3 10:26:00... (1 Reply)
Discussion started by: srini123
1 Replies
Login or Register to Ask a Question