Tools‎ > ‎Ubuntu/Linux server‎ > ‎

Replace string in file

# replace and write edited version into new file
sed 's/oldstring/newstring/g' file.txt > new_edited_file.txt

# to use with Linux pipe |
cat file.txt | sed 's/oldstring/newstring/g' > new_edited_file.txt


# edit directly in original file
: replace original file with new edited version (option -i)

sed -i 's/oldstring/newstring/g' file.txt