* Peter Müller <c-major@web.de> [20070805 10:18]: > ich möchte gerne Zeilenumbrüche in einer Datei ersetzen und krieg's > nicht hin! Siehe sed FAQ, 5.10 ,--[ http://sed.sourceforge.net/grabbag/tutorials/sedfaq.txt ]-- |5.10. Why can't I match or delete a newline using the \n escape sequence? | Why can't I match 2 or more lines using \n? | | The \n will never match the newline at the end-of-line because the | newline is always stripped off before the line is placed into the | pattern space. To get 2 or more lines into the pattern space, use | the 'N' command or something similar (such as 'H;...;g;'). | | Sed works like this: sed reads one line at a time, chops off the | terminating newline, puts what is left into the pattern space where | the sed script can address or change it, and when the pattern space | is printed, appends a newline to stdout (or to a file). If the | pattern space is entirely or partially deleted with 'd' or 'D', the | newline is *not* added in such cases. Thus, scripts like | | sed 's/\n//' file # to delete newlines from each line | sed 's/\n/foo\n/' file # to add a word to the end of each line | | will _never_ work, because the trailing newline is removed _before_ | the line is put into the pattern space. To perform the above tasks, | use one of these scripts instead: | | tr -d '\n' < file # use tr to delete newlines | sed ':a;N;$!ba;s/\n//g' file # GNU sed to delete newlines | sed 's/$/ foo/' file # add "foo" to end of each line | | Since versions of sed other than GNU sed have limits to the size of | the pattern buffer, the Unix 'tr' utility is to be preferred here. | If the last line of the file contains a newline, GNU sed will add | that newline to the output but delete all others, whereas tr will | delete all newlines. | [...] `-- Grüße, Felix -- Felix M. Palmen (Zirias) \ -PGP- <fmp@palmen.homeip.net> /"\ ASCII Ribbon web: http://zirias.ath.cx/ \ http://zirias.ath.cx/pub.txt \ / Campaign my open source projects: \ FP ED9B 62D0 BE39 32F9 2488 X Against HTML In http://zirias.ath.cx/?pg=pro \ 5D0C 8177 9D80 5ECF F683 / \ Mail And News
Attachment:
signature.asc
Description: Digital signature