Hello
I need help with replacing string in a text file with another string read from another file.
I have the following
file1
first_line
10.0.0.0 end_of_line mystring
10.0.0.0 end_of_line mystring
10.0.0.0 end_of_line mystring
the_rest
file2
10.1.1.1 next_string
10.1.1.2 next_string
10.1.1.3 next_string
I would like to have the output file3 to look like this
first_line
10.1.1.1 end_of_line next_string
10.1.1.2 end_of_line next_string
10.1.1.3 end_of_line next_string
the_rest
I wrote a small script but the sed didn't seem to work within a bourne shell script
#!/bin/sh
while read entry
do
string1=`echo $entry | awk '{print $1}'`
string2=`echo $entry | awk '{print $2}'`
cat file1 | sed '1,/10.0.0.0/s//'"$string1"'/' | sed '1,/my_string/s//'"$string2"/' > file3
done < file2
The output always came out like this for me
first_line
10.1.1.3 end_of_line next_string
10.1.1.3 end_of_line next_string
10.1.1.3 end_of_line next_string
the_rest
Thanks in advance for your help
LT
I need help with replacing string in a text file with another string read from another file.
I have the following
file1
first_line
10.0.0.0 end_of_line mystring
10.0.0.0 end_of_line mystring
10.0.0.0 end_of_line mystring
the_rest
file2
10.1.1.1 next_string
10.1.1.2 next_string
10.1.1.3 next_string
I would like to have the output file3 to look like this
first_line
10.1.1.1 end_of_line next_string
10.1.1.2 end_of_line next_string
10.1.1.3 end_of_line next_string
the_rest
I wrote a small script but the sed didn't seem to work within a bourne shell script
#!/bin/sh
while read entry
do
string1=`echo $entry | awk '{print $1}'`
string2=`echo $entry | awk '{print $2}'`
cat file1 | sed '1,/10.0.0.0/s//'"$string1"'/' | sed '1,/my_string/s//'"$string2"/' > file3
done < file2
The output always came out like this for me
first_line
10.1.1.3 end_of_line next_string
10.1.1.3 end_of_line next_string
10.1.1.3 end_of_line next_string
the_rest
Thanks in advance for your help
LT