In-place edits with sed on OS X

I’d like edit a file with sed on OS X. I’m using the following command: sed ‘s/oldword/newword/’ file.txt The output is sent to the terminal. file.txt is not modified. The changes are saved to file2.txt with this command: sed ‘s/oldword/newword/’ file1.txt > file2.txt However I don’t want another file. I just want to edit file1.txt. … Read more

What is the difference between `sorted(list)` vs `list.sort()`?

list.sort() sorts the list and replaces the original list, whereas sorted(list) returns a sorted copy of the list, without changing the original list. When is one preferred over the other? Which is more efficient? By how much? Can a list be reverted to the unsorted state after list.sort() has been performed? 6 Answers 6

How to delete from a text file, all lines that contain a specific string?

How would I use sed to delete all lines in a text file that contain a specific string? 20 20 To remove the line and print the output to standard out: sed ‘/pattern to match/d’ ./infile To directly modify the file – does not work with BSD sed: sed -i ‘/pattern to match/d’ ./infile Same, … Read more