Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove file coding mark but preserve its coding

Tags:

linux

shell

utf-8

I've got a file with UTF-8 (Without BOM) coding. File is being created on Windows site and it's being transfered to Linux server through SFTP. Using cat -e on it, I get something like this:

cat -e file.txt

M-oM-;M-?test13;hbana0Kw;$
lala;LjgX$

Now, I know that M-oM-;M-? stands for UTF-8 (Without BOM). Is there a way to remove it from file but preseve its coding?

like image 790
NRG Avatar asked Nov 24 '14 12:11

NRG


1 Answers

To remove the BOM from the first line of a file you can use something like this sed -e '1 s/^.//' file.txt.

sed commands have two parts an address and a command. Most of the time you see sed used without addresses (which means apply to all lines) but you can restrict the command operation to only specific lines by using addresses.

In this case the address is 1 meaning the first line. So the replacement only applies to the first line and every line is printed (as that is the default sed behaviour).

like image 65
Etan Reisner Avatar answered Oct 11 '22 14:10

Etan Reisner