Canonical vs. non-canonical terminal input

For canonical input — think shell; actually, think good old-fashioned Bourne shell, since Bash and relatives have command-line editing. You type a line of input; if you make a mistake, you use the erase character (default is Backspace, usually; sometimes Delete) to erase the previous character. If you mess up completely, you can cancel the … Read more

Replace a string in shell script using a variable

If you want to interpret $replace, you should not use single quotes since they prevent variable substitution. Try: echo $LINE | sed -e “s/12345678/${replace}/g” Transcript: pax> export replace=987654321 pax> echo X123456789X | sed “s/123456789/${replace}/” X987654321X pax> _ Just be careful to ensure that ${replace} doesn’t have any characters of significance to sed (like / for … Read more

sed edit file in place

The -i option streams the edited content into a new file and then renames it behind the scenes, anyway. Example: sed -i ‘s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g’ filename while on macOS you need: sed -i ” ‘s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g’ filename