1

I am working on a Shell script and I need to replace only number on line 13 with a number from another file.

file1:

line1
line2
...
Text: 95%
...

file2:

98.4256

The result should look like this:

file1:

...   
Text: 98.4256%
...

Basically I need to replace the number before % in file1 on line 13 with a number from file2 (the number in file2 is on line 1).

Thanks in advance for any tips.

Jack Payne
  • 49
  • 1
  • 1
  • 6

1 Answers1

0
sed "4 s/:.*/: $(cat file2)%/" file1
line1
line2
...
Text: 98.4256%
...

Change 4 to any other number of your requirement.

Contents of file1

cat file1
line1
line2
...
Text: 95%
...

Contents of file2

cat file2
98.4256
P....
  • 17,421
  • 2
  • 32
  • 52
  • Thank you. As I wanted to save the changes as well, and cannot use `-i` on my HP-UX system, I was able to save the changes with this "workaround": `sed "4 s/:.*/: $(cat file2)%/" file1 > file1.tmp && mv file1.tmp file1` – Jack Payne Jan 11 '17 at 12:24