Get the App
SLTechnology News&Howtos  ›  Servers  › 

Sed processes dos CR/LF in files

Shulou Source: shulou.com Published: 2022-06-02 18:46:00 09月22日 Update

Replace the dos control character ^ M

# IN unix ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format)

Sed's / ^ M $/ /'# in bash/tcsh, press Ctrl-V then Ctrl-M

Sed's Universe. Assumes that all lines end with CR/LF.

Sed's /\ x0DharmAccord'# gsed 3.02.80, but top script is easier

# IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format

Sed "spockets" / `echo-e\ r` / "# command line under ksh

Sed's Universe'"/ `echo\ r` /" # command line under bash "

Sed "spockets / `echo\ r` /" # command line under zsh

Sed's _ gsed /\ r _

# IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format

Sed "sswab" / "# method 1"

Sed-n p # method 2

# IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format

# Cannot be done with DOS versions of sed. Use "tr" instead.

Tr-d\ r outfile # GNU tr version 1.22 or higher

Example: delete all blank lines and lines consisting of spaces in the file

$cat ifile | sed'/ ^ $/ d' | sed'/ ^ [[: space:]] * $/ d' # method 1

$cat ifile | sed-e'/ ^ $/ d'- e'/ ^ [[: space:]] * $/ d'# method 2

Tags: Files characters spaces blank lines controls processing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info MariaDB Shulou Technology macOS