
$ sudo sed -i.bak ':read N $!b read s/\r\n/\n/g s/\r/\n/g' /var/log/apt/term. var/log/apt/term.log: UTF-8 Unicode text, with CRLF, CR, LF line terminators, with escape sequences, with overstriking Since sed 's///' file reads a line from the file, performs the substitution on it, prints the result, reads the next line and so on, \n cannot be used within the part.īut if we have the whole file as a single line in the pattern space, we will be able to use \n within the part, and this is necessary to distinguish between the sequence \r\n and "lonesome" \rs.Įxample: $ sudo file /var/log/apt/term.log The first substitution replaces each \r\n with \n.Īfter this, the remaining ("lonesome") \rs are replaced with \n. Without, the command applies for current line only. ) Try :s/M/r/g instead to remove M and replace M with newline character r. This is repeated until the last line is reached, then the substitutions operate on the pattern space, which contains the whole file as a single line, which is the reason why we need the g flag for the substitutions. If you have a file with M at the end of some lines and you want to get rid of them, use this in Vim: (Press Ctrl + V Ctrl + M to insert that M. N adds a newline to the pattern space, then appends the next line of input (with any trailing \n removed) to the pattern space. So when the cycle starts (we have just one cycle here), sed reads the first line of input, removes any trailing \n and places it in the pattern space, then it processes the script:
Linux untar .xml archive#
For those wondering what the options do, from man tar: -x, -extract, -get extract files from an archive -v, -verbose verbosely list files processed -f, -file ARCHIVE use archive file or device ARCHIVE. $!: Don't execute the following command on the last line. Drop the space after -, or even drop - entirely: tar xvf grads-2.0.2.N: Adds a newline to the pattern space, then appends the next line of input (with any trailing \n removed) to the pattern space. It is an archive file with several other files inside it, which is then compressed.You also may omit -i and redirect the output to an arbitrary file. i tells sed to replace your file with the result of the script,Īnd if you supply a SUFFIX, a backup will be created with that suffix. f: File, name of the tar file we want tar to work with. j: Bzip2, use bzip2 to decompress the tar file. v: Verbose, list the files as they are being extracted.

tar.bz2 file were: -x: Extract, retrieve the files from of the tar file.
\r\n and \r, you can use this sed script (this is an all-in-one solution and of course, you can also use it if your file merely has \r\n or \r line breaks): To be clear, the command line options we used with tar for the. You can also use tar -zxvf