This is a reminder of how to remove and replace line feed codes in text and replace binary data on Linux. It can also be run on Windows by Windows users by installing cygwin or WSL2, and If you install git, you can easily convert it with the commands available as a subset of git-bash.
Specifically, you can use the
xxd command to replace the binary data with hexadecimal text and then do the conversion.
This is a reminder to preparetion (pass) for git user.
If you already have
xxd command available, skip it.
Once you have the PATH env, you can run the Linux commands installed with git-bash from any command prompt at your Windows.
From thekey menu, select git-bash Application and launch.
Once git-bash is up, type
where xxd to know where is the xxd executable.
Now that we know that the location is
C:\Program Files\Git\usr\bin\, we can add this path to the PATH env in System Preferences.
Add this path to your PATH in System Preferences.
The Linux commands
tr can be used to read and
xxd command can handle them well.
This is an example of how to remove the line feed code from a UTF-8 text file whose line feed code is CR LF.
Let's output test_oneline.txt, in which the newline code is removed from the text.txt file as shown below.
squirrel watermelon kangaroo
Actually, let's remove the newline code from the text.txt file.
xxd -p -c 68719476736 test.txt | sed s/0d0a//g | xxd -p -r > test_oneline.txt
The resulting file will look like this, with the newlines removed!
xxd command can output the contents of a file as hexadecimal text data, or vice versa, back to binary data.
The procedure, with the newline code removed, is as follows:
The options for the
xxd command are as follows
|-p||Standard output in hexadecimal text|
|-c||Specifies the number of hexadecimal digits to output per line. The default is 16; if the number exceeds 16 columns, the line will be broken accordingly. For example, if you specify "68719476736", you can output up to 64GB without line feeds.|
|-r||Read hexadecimal numbers in text and output as binary to standard output|
|2021-Dec-15||Added the use of git-bash to the xxd command|
Thank you for your message.
Sorry. The Error has occurred.We apologize for the inconvenience.Please try again in a few minutes or contact us via DM below.Twitter:@NodachiSoft_engName:
Send the following information to us. If you are happy with your submission, please click "Send". If you want to modify it, please click "Back".Name: