sed script for search and replacement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed script for search and replacement
# 1  
Old 03-27-2009
sed script for search and replacement

New to scripting.. think i need sed to do the following but need help.

have a properties files with variable i need to replace using substitution

for e.g in x.properties

xslt.root.dir=/apps1/test/cs.war/presentation/xsl

have a shell script with following

echo "Edit '/tmp/x.properties'"
echo "-----------------------------------------------------------------------------"
echo "Modify 'xslt.root.dir=' with the environment specific path"
echo "xslt.root.dir=$PWD/presentation/xsl"
echo ""

(need command here to replace xslt.root.dir= variable in x.properties with either a variable read in from command line or $PWD variable)

echo "Press [Enter] when file has been modified"
read $ANS
echo ""
echo "Edit '/tmp/leena/web.xml'"
echo "-----------------------------------------------------------------------------"
echo "Modify '/apps1/instance_t05/edi/fatwire' with the environment specific path"
echo "$PWD"
echo ""
echo "Press [Enter] when file has been modified"
read $ANS
echo ""
# 2  
Old 03-27-2009
Paste the entire script here, using the CODE tags to make it a bit easier
# 3  
Old 03-27-2009
have a properties files with variables i need to replace using substitution in a shell script

for e.g in

x.properties

Code:
xslt.root.dir=/apps1/test/cs.war/presentation/xsl

have a shell script with following

Code:
echo "Edit '/tmp/x.properties'"
echo "-----------------------------------------------------------------------------"
echo "Modify 'xslt.root.dir=' with the environment specific path"
echo "xslt.root.dir=$PWD/presentation/xsl"
echo ""

(need command here to replace xslt.root.dir= variable in x.properties with either a variable read in from command line or $PWD variable) 

echo "Press [Enter] when file has been modified"
read $ANS
echo ""
echo "Edit '/tmp/leena/web.xml'"
echo "-----------------------------------------------------------------------------"
echo "Modify '/apps1/instance_t05/edi/fatwire' with the environment specific path"
echo "$PWD"
echo ""
echo "Press [Enter] when file has been modified"
read $ANS
echo ""
Image

# 4  
Old 03-27-2009
Quote:
Originally Posted by cookie23patel
have a properties files with variables i need to replace using substitution in a shell script

for e.g in

x.properties

Code:
xslt.root.dir=/apps1/test/cs.war/presentation/xsl

have a shell script with following

Code:
echo "Edit '/tmp/x.properties'"
echo "-----------------------------------------------------------------------------"
echo "Modify 'xslt.root.dir=' with the environment specific path"
echo "xslt.root.dir=$PWD/presentation/xsl"
echo ""

(need command here to replace xslt.root.dir= variable in x.properties with either a variable read in from command line or $PWD variable) 

echo "Press [Enter] when file has been modified"
read $ANS
echo ""
echo "Edit '/tmp/leena/web.xml'"
echo "-----------------------------------------------------------------------------"
echo "Modify '/apps1/instance_t05/edi/fatwire' with the environment specific path"
echo "$PWD"
echo ""
echo "Press [Enter] when file has been modified"
read $ANS
echo ""
Image

I'm still extremely new to sed and all this, but I did a test and it replaced the one thing you needed replaced. But i'm sure there is a better shorter way to do this:
Code:
sed -i "s:xslt.root.dir=.*:xslt.root.dir=$PWD/presentation/xsl:" test2

test2 is the name of the file, so if you can easily do this to multiple files if needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Busybox search replacement for find

Hi, I am looking for a solution to find files in a folder and subfolders. Those files should be moved (some with spaces) when they were between 2015 Feb. 03 and 2014 Nov. 24. find . -type f -newermt "2010-01-01" ! -newermt "2010-06-01" I am working on a QNAP with a small busybox.... (2 Replies)
Discussion started by: krischeu
2 Replies

2. Shell Programming and Scripting

Recursive replacement of search string using sed

Dear Unix Forum Group Members, Please do let me know how I can replace the double pipe with single pipe recursively on single record. Sample Input Data: DN set|Call prefix||| Called number address nature 0||| *789|||||||ALL number types 0||| 00||||||||ALL number types 10||... (5 Replies)
Discussion started by: srinu.kadem
5 Replies

3. Shell Programming and Scripting

SED replacement

Hi, i have a file with lines, file.txt ------- test is fun testing is better I need to replace 'test' to 'develop' and i used, a=test b=develop sed "s,$a,$b,g" -------- but i see the word 'testing' is also replaced. Need some solution. Is there any way i could replace only 'test' ? (4 Replies)
Discussion started by: giri_luck
4 Replies

4. Shell Programming and Scripting

Replacement with sed

I am trying to replace the line which has string "tablespace" not case senstive.... with below simple script: mysrcipt.sh sed "s/.*/TABLESPACE USERS/g" create_table > tmp mv tmp create_table Is there any better way to do it? If Search string tooooooo long it will be tough to code in... (4 Replies)
Discussion started by: ganeshd
4 Replies

5. Shell Programming and Scripting

Help with sed replacement

This seems like it should be an easy problem, but I'm a noob and I can't figure it out. I'm trying to use sed, but would be happy to use anything that does the job. I am trying to trim off a fixed number of unknown characters from 2 different : delimited fields while keeping the intervening... (4 Replies)
Discussion started by: helix_w
4 Replies

6. UNIX for Dummies Questions & Answers

global search and replacement of a non-ascii character

Hi, I need to do a global search and replacement of a non-ascii character. Let me first give the background of my problem. Very frequently, I need to copy set of references from different sources. Typically, a reference would like this: Banumathy et al., 2002 G. Banumathy, V. Singh and U.... (1 Reply)
Discussion started by: effjay
1 Replies

7. Shell Programming and Scripting

search for any number, and retain them in replacement

Hello! Here is what I am trying to do: I am taking a class at school that is using a lot of literature that is in the public domain, and available for free on the web. Rather than read them online in HTML, I have been pulling them down and quickly and dirtily tagging them up and typesetting... (4 Replies)
Discussion started by: ccox85
4 Replies

8. Shell Programming and Scripting

Need Replacement for sed

Hi Can anyone provide me the replacement of sed with xargs perl syntax for the below sed -e :a -e '/;$/!N;s/\n//; ta' -e 's/;$//' This should be without looping has to take minimal time for search (0 Replies)
Discussion started by: dbsurf
0 Replies

9. Shell Programming and Scripting

Need shell/sed script for grep+string replacement

Hi, Let me explain the situation. There are many files in a directory and its sub-directories that conatin the string pattern "pa". I want to replace all such instances with the pattern "pranavagarwal" doing a grep "pa" `ls` does give me all the instances of the occurence of that... (3 Replies)
Discussion started by: pranavagarwal
3 Replies

10. UNIX for Dummies Questions & Answers

Replacement using sed

Hi I have the following file that i need to run a sed command on 1<tab>running 2<tab>running 3<tab>running 4<tab>running I want to be able to replace a line i.e the second one with '2<tab>failed'. As the first number is unique that can be used to search for the relevant line (using ^2 i... (5 Replies)
Discussion started by: handak9
5 Replies
Login or Register to Ask a Question

Featured Tech Videos