====== Sed ====== [[wp>sed|sed]], a stream editor. ===== Usage ===== ==== Replace ==== Replace ''word'' with ''words'' from file: sed -i 's|word|words' file Replace multiple target (sperate with '';''): sed -i 's|word|words;s|hello|bye' file ==== Delete ==== Delete lines contain ''import'': sed -i '/import/d' file Delete lines contain ''import'' **and the next line**: sed -i '/import/,+1d' file Delete specify line by line number [(cite:>[[http://stackoverflow.com/a/6022431|bash tool to get nth line from a file]])] sed -i "${NUM}q;d" file ==== Create backup file ==== Directly modify file and create a backup file: sed -i.bak 's/test/ok/g' file ===== Reference ===== * https://www.gnu.org/software/sed/manual/sed.html * http://www.grymoire.com/Unix/Sed.html * https://www.digitalocean.com/community/tutorials/the-basics-of-using-the-sed-stream-editor-to-manipulate-text-in-linux