10 ms·
I use ed in scripts when you need to modify a file in place, something that you can’t do with sed.
by pmarin 8y ago
I use ed in scripts when you need to modify a file in place, something that you can’t do with sed.
- harshreality 8y ago`sed -i ...` ?
- bonzini 8y agoGNU sed has supported sed -i for about 15 years; BSD sed supports it too but you have to write sed -i ''. The difference is that ed reads the entire input in memory, but it doesn't break symlinks. sed's in-place editing mode (just like perl -i or the newer awk -i inplace that is supported by GNU awk) breaks symlinks, on the other hand it can operate on arbitrarily large files.
- maccio92 8y agoso... you can't use sed for the same task because it breaks symlinks?
- LukeShu 8y agoBy "breaks symlinks", he means that if you run `sed -i` (without `--follow-symlinks`) on a symlink, then it will turn the symlink in to a regular file. GNU sed has `--follow-symlinks` which adjusts this behavior to edit the target of the symlink, and leave the symlink itself alone.
- deleted 8y ago[deleted]
- ibotty 8y ago> [BSD sed] you can also do sed -i -e 's/a/b/' file which will work for GNU and BSD sed.
- bonzini 8y agoNo, it doesn't. On BSD sed it will produce a backup file named file-e. The portable way is to use-i.bak and then get rid of the backup file.
- LukeShu 8y agoGNU sed has `--follow-symlinks` to have `sed -i` avoid turning symlinks in to regular files.
- bonzini 8y agoIt would still break hard links though.
- a1369209993 8y agoIf you have hard links your file system is broken.
- emidln 8y agosed -i'' ?
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]