head buried in sed

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#21 Post by DMcCunney »

technosaurus wrote:I never could figure out how to easily replace an existing "new line" \n with a different character |,\t(tab) .... probably because it is a LINE editor and that would make it a lineS editor.
It is a lineS editor. Run sed on a file, and it reads each line of the file and runs the edit commands/script you passed to it on the line, then reads the next. When it's processed all lines, it exists.

As for changing line endings:

Code: Select all

TEXT CONVERSION AND SUBSTITUTION:

 # IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
 sed 's/.$//'               # assumes that all lines end with CR/LF
 sed 's/^M$//'              # in bash/tcsh, press Ctrl-V then Ctrl-M
 sed 's/\x0D$//'            # works on ssed, gsed 3.02.80 or higher

 # IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format.
 sed "s/$/`echo -e \\\r`/"            # command line under ksh
 sed 's/$'"/`echo \\\r`/"             # command line under bash
 sed "s/$/`echo \\\r`/"               # command line under zsh
 sed 's/$/\r/'                        # gsed 3.02.80 or higher

 # IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format.
 sed "s/$//"                          # method 1
 sed -n p                             # method 2

 # IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
 # Can only be done with UnxUtils sed, version 4.0.7 or higher. The
 # UnxUtils version can be identified by the custom "--text" switch
 # which appears when you use the "--help" switch. Otherwise, changing
 # DOS newlines to Unix newlines cannot be done with sed in a DOS
 # environment. Use "tr" instead.
 sed "s/\r//" infile >outfile         # UnxUtils sed v4.0.7 or higher
 tr -d \r <infile >outfile            # GNU tr version 1.22 or higher
from http://sed.sourceforge.net/sed1line.txt
______
Dennis

Post Reply