sed command do in a script?sed is a tool that edits text by searching and replacing patterns. It reads input line by line and can change text automatically.
sed?The basic form is sed 's/old/new/'. It means: find old and replace it with new in each line.
g flag do in sed 's/old/new/g'?The g flag means "global". It replaces all occurrences of old in each line, not just the first one.
sed to replace text in a file and save the changes back to the file?Use the -i option: sed -i 's/old/new/g' filename. This edits the file directly.
sed substitution, like sed 's|old|new|g'?Using different delimiters helps when the text contains slashes /. It avoids confusion and makes the command easier to read.
sed 's/apple/orange/' do?This command replaces the first occurrence of 'apple' with 'orange' on each line.
pets.txt and save changes directly?The -i option edits the file in place, saving changes directly.
sed 's|path/to/old|path/to/new|g' instead of sed 's/path\/to\/old/path\/to\/new/g'?Using | as delimiter avoids needing to escape slashes, making the command easier to read.
sed 's/old/new/' without the g flag?Without g, only the first match per line is replaced.
sed -i?Using -i alone edits the file in place without backup (behavior may vary by system).
sed to replace all occurrences of a word in a text file and save the changes.sed substitution commands can be helpful.