[英]Remove ^@ characters from linux file
I have a file which has visible ^@
characters (blue) after each character.我有一个文件,每个字符后都有可见的^@
字符(蓝色)。 I can see these characters only in vi file.txt
.我只能在vi file.txt
看到这些字符。 I am unable to view these characters using cat
.我无法使用cat
查看这些字符。 How can I remove them?我怎样才能删除它们?
I tried using the following command:我尝试使用以下命令:
sed "s/[^@]//g" a.txt > b.txt
However this didn't seem to alter the file.然而,这似乎并没有改变文件。
试试iconv -f UTF16 -t UTF8 <your-file> > <new-file>
dos2unix file.txt file.txt
. dos2unix file.txt file.txt
。 This will do..这会做..
这有效:
sed "s/[\^@]//g" a.txt > b.txt
I remove all files in dir with inappropriate symbols in a such way:我以这种方式删除 dir 中带有不适当符号的所有文件:
for i in *.*;do
case "$i" in
*[\(\)\!\*\%\^\ ]*)
mv "$i" ${i//[^a-zA-Z0-9.]/_}
;;
esac
done
[()!*%^\\ ] -- stands for eliminate any symbol from the set of: ()!*%^ and space [^a-zA-Z0-9.] -- stands for not English low and upper cases charecters, numbers and dots [()!*%^\\] -- 代表从以下集合中消除任何符号: ()!*%^ 和空格 [^a-zA-Z0-9.] -- 代表非英文大小写字符、数字和点
What is important it only renames files containing 'bad' characters.重要的是它只重命名包含“坏”字符的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.