Prev: SED help -
Next: AIX iconv question
From: pgas on 5 Oct 2009 01:57 Jon LaBadie <jlabadie(a)axcxm.org> wrote: > James Michael Fultz wrote: >> $ printf ',s/\r$//\nwq\n' | ed -s file >> > When did ed learn \r == ^M and > when did it learn two letter commands? The \r is interpreted by printf so ed doesn't see it. wq is not posix (and in fact just w would do) but it is understood by some ed implementations. -- pgas @ SDF Public Access UNIX System - http://sdf.lonestar.org
From: pgas on 5 Oct 2009 02:07 pk <pk(a)pk.invalid> wrote: > Kenny McCormack wrote: > >> so you might want to use an editor that re-writes files in place (not just >> pretends to like the -i switches found in various seds, perls, etc). I >> believe the original vi did this (re-writes in place) and that current VIM >> can be made to do so by setting the right options (alas, it doesn't do it >> by default). > > Just curious, how does one do true inplace editing when the length of the > new text differs from the original? It seems to me that it would need > moving forward/backwards the non-edited text to accommodate for that, which > seems like an expensive thing to do if the file is huge (and probably > unsafe in the case of a crash). Well I guess, here you should read true inplace as "doesn't change the inode number". Where the data really go is probably lost in the caches and filesystems and drivers and hardware implementations. In most cases it doesn't matter and it doesn't even avoid a temp file as I believe ed and ex/vi use temporary files internally, but sometimes sed -i behaviour is not what you want. A common example is if you use sed -i on a symbolic link to a file, it will create a modified copy and remove the link rather changing the file. In such cases I do think that the gnu sed interpretation of "inplace" is a bit misleading. ( IIRC the next version of sed will provide more control over this) -- pgas @ SDF Public Access UNIX System - http://sdf.lonestar.org
From: Kenny McCormack on 5 Oct 2009 06:22 In article <hac1s6$b96$1(a)chessie.cirr.com>, pgas <pierre.gaston(a)gmail.com> wrote: >Jon LaBadie <jlabadie(a)axcxm.org> wrote: >> James Michael Fultz wrote: >>> $ printf ',s/\r$//\nwq\n' | ed -s file >>> >> when did it learn two letter commands? > >wq is not posix (and in fact just w would do) but it is understood >by some ed implementations. That's why I always use "ex" in the above syntax, not "ed". Songs about horses notwithstanding, I consider "ed" to be the beta version of the Unix command line editor concept. Always use "ex".
From: James Michael Fultz on 5 Oct 2009 19:01
* pgas <pierre.gaston(a)gmail.com>: >> James Michael Fultz wrote: >>> $ printf ',s/\r$//\nwq\n' | ed -s file [...] > wq is not posix (and in fact just w would do) but it is understood > by some ed implementations. Good to know. I guess I had vi on the brain at the time. :-) -- James Michael Fultz <xyzzy(a)sent.as.invalid> Remove this part when replying ^^^^^^^^ |