Find and replace text within a file using sed command. Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input. The s is the substitute command of sed for find and replace. It tells sed to find all occurrences of 'old-text' and replace with 'new-text' in a file named input.