Replacing partial content of a file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing partial content of a file.
# 1  
Old 07-16-2014
Replacing partial content of a file.

Hi All,
Please help me in the below issue.I had a file called env.prop.In that i need to change service.url.If i select chocie 2.

it should come as https://dev2.ecif.info53.com:30102/soap/default

30102 port is not fixed .It varies when the file is updated.So i want to keep orginal port in the orginal file.

Sample files:
Code:
cat env.prop
ffusion.bpwServices.url=https://history.info53.com:${port.prefix}43/bw/services^M
ffusion.bpwServices.username=
ffusion.bpwServices.password=[ENC]4D97EE8B41F0CD7703041EBAD31924AFXB1447B48^M
service.url=https://dev3.ecif.info53.com:30102/soap/default
Another file like below:
cat env.prop
ffusion.bpwServices.url=https://history.info53.com:${port.prefix}43/bw/services^M
ffusion.bpwServices.username=
ffusion.bpwServices.password=[ENC]4D97EE8B41F0CD7703041EBAD31924AFXB1447B48^M
service.url=https://dev2.ecif.info53.com:30002/soap/default

like many files..

My code:I not able to capture the port from original file..
Code:
if [ ${choice2} = "1" ]
then
ECIFSERVER=dev1.ecif.info53.com
elif [ ${choice2} = "2" ]
then
ECIFSERVER=dev2.ecif.info53.com
elif [ ${choice2} = "3" ]
then
ECIFSERVER=dev3.ecif.info53.com
else
   echo "Invalid choice... Please run the script again and choose a valid option"
    echo " "
    exit 1
fi
 
LINE=`cat environment.properties | grep ^service.url=`
sed s!${LINE}!service.url=https://${ECIFSERVER}:xxxxx/soap/default!g environment.properties > tmp.properties
mv -f tmp.properties environment.properties

Let me know you had any questions.

I am unix AIX machine.
I am using /usr/bin/ksh
# 2  
Old 07-16-2014
What output are you hoping to produce from your two sample input files?
# 3  
Old 07-16-2014
try with nawk (instead of your sed command )

Code:
nawk -F: -v url="$ECIFSERVER" 'BEGIN{OFS=":"}/service.url/{$2=url}1' environment.properties > tmp.properties

# 4  
Old 07-18-2014
Hi itkamaraj,

Thanks a lot it's working as expected..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Partial file pulling

I am connecting to another server through sftp. I am running one batch script to pull file from another server. sometimes i am receiving partial files. I am using below commands in batch script. ls -ltr new.txt mget new.txt bye The file is of 1 MB only.In most of the cases , i received... (6 Replies)
Discussion started by: srinath01
6 Replies

3. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

4. Shell Programming and Scripting

Partial content greping into a 3rd file

Hi, I do have couple of files in folder. The names of each of the files have a pattern. B_A17_A17_1T.txt B_A17_A17_2T.txt B_A17_A17_3T.txt B_A17_A17_7T.txt ..... ..... B_A17_A17_45T.txt Each of the above files have the same pattern of data with 4 columns and have an header for... (10 Replies)
Discussion started by: Kanja
10 Replies

5. Shell Programming and Scripting

How to replace partial of string in file?

Hi Guys, I need replace part of string in a file. for example: ABC=123 CDE=122 DEF=456 ABC=123 DED=333 ABC=123 I need replace the value after ABC=, highlighted in red. I want to get following result; ABC=456 CDE=122 DEF=456 ABC=456 DED=333 ABC=456 Anybody can help me this. ... (8 Replies)
Discussion started by: ken6503
8 Replies

6. Shell Programming and Scripting

Pattern Matching & replacing of content in file1 with file2

I have file 1 & file 2 with content mentioned below. I want to get the output as shown in file3. Requirement: check the content of column 1 & column 2, if value of column 1 in file1 matches with first column of file2 then remaining columns(2&3) of file2 should get replaced, also if value of... (4 Replies)
Discussion started by: siramitsharma
4 Replies

7. Shell Programming and Scripting

AWK - Print partial line/partial field

Hello, this is probably a simple request but I've been toying with it for a while. I have a large list of devices and commands that were run with a script, now I have lines such as: a-router-hostname-C#show ver I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Discussion started by: ippy98
3 Replies

8. Shell Programming and Scripting

Replacing content from a list

Okay, so I am not quite sure the best way of going about this. I have a whole stack of files that need items replaced with a code corresponding to it. In particular, I am looking to replace the names of countries with the two letter iso country code. The files themselves are in csv format with... (4 Replies)
Discussion started by: johnlee
4 Replies

9. Shell Programming and Scripting

Query for replacing a string and keeping the non-replaced content

Hi experts, As i am a novice unix player...so need help for the below query...banged my head from quite a while...:confused: i have a set of html files, in which i need to search for string "Page"(case sensitive) and then replace the same with some numeric code ,say, "XXX1234". Here in... (2 Replies)
Discussion started by: rahulfhp
2 Replies

10. Shell Programming and Scripting

Replacing a paragraph between pattern , with the content 4m another file

hi, i wanted to put the output of file f1 into the pattern space of file f2 f1: wjwjwjwjwjwjwj //these line go in file f2 jwjwjwjwjwjjwjw wjwjwjwjjwjwjwj f2: Pattern_start __________ //these are the line to be replaced __________ Pattern_end i m... (4 Replies)
Discussion started by: go4desperado
4 Replies
Login or Register to Ask a Question