<\/span><\/h2>\nThis will remove word, word1, or word2 from the file input.txt<\/p>\n
sed 's\/word\\|word1\\|word2\/\/g' input.txt<\/pre>\n<\/span>Change the first instance on each line <\/strong><\/span><\/h2>\nThis will substitute the 1 instance of the word dog for cat on each line.<\/p>\n
sed 's\/dog\/cat\/1' newfile.txt<\/pre>\n<\/span> Change case<\/strong><\/span><\/h2>\nThis will change all the text to uppercase.<\/p>\n
\u00a0sed -e 's\/.*\/\\U&\/g' input.txt<\/span><\/pre>\nTo only change a sub section of text to lower case then the following can be used (this will match everything between the first set of “).<\/p>\n
sed -r 's\/(^.*\".*\\\" \\{)\/\\L\\1\/' input.txt<\/pre>\n<\/span>Changing multiple files<\/strong><\/span><\/h2>\nBelow will change all the files in \/etc from word1 to word2.<\/p>\n
sed -i 's\/word1\/word2\/g' \/etc\/*<\/pre>\n<\/span>Insert Line<\/strong><\/span><\/h2>\nThe following will insert a line with the string “hello” on the 6th line.<\/p>\n
sed 6i\\hello yourfile.txt<\/pre>\n<\/span>Remove 4 digits
\n<\/strong><\/span><\/h2>\nThe following will remove 4 digits from the beginning of the line.<\/p>\n
sed 's\/^[0-9]\\{4\\}\/\/g' yourfile.txt<\/pre>\n