Tag Archives: txt

[Solved] Linux — 9 — txt files are copied from windows to Linux and read error

Reason: different coding methods

Solution:

Modify the CFG configuration file in Linux, create a new CFG text file, copy and paste it into the new CFG. File file name to view the encoding method of the file.

How to convert in Linux?

Convert CFG files in folders 1 and 2 [UTF-8 (with BOM) to UTF-8]:

#!/bin/bash

function cfg_change()
{
	dir=./etc/xxx/"$1"/
	find $dir -type f -name "cfg.txt" -print | xargs -i sed -i '1 s/^\xef\xbb\xbf//' {}
	echo "-------Convert Succeed-------"
	file ./etc/xxx/"$1"/cfg.txt
}

case "$1" in
	-1)
		cfg_change 1;
    ;;
	-2)
		cfg_change 2;
	;;
	*)
		echo "Usage: $0 -1|-2"
esac

exit 0