当前位置: 首页 > news >正文

macOS 使用 iconv 转化文件编码

文章目录

    • 使用方式
    • 支持的编码类型
    • iconv 更多用法


使用方式

iconv  -f GB2312 -t UTF-8  分治算法.txt > 分治算法2.txt 

支持的编码类型


可以使用 下面命令 查看编码类型

iconv -l

PS : ISO-8859 有很多种分支,iconv 支持 ISO-8859-1、ISO-8859-10,但不支持 ISO-8859,否则可能报如下错误:

$ iconv  -f ISO-8859   -t UTF-8  分治算法.txt  [0]
iconv: iconv_open(UTF-8, ISO-8859): Invalid argument

这样就不会报错

iconv  -f ISO-8859-1   -t UTF-8  分治算法.txt

但具体文件编码类型,建议使用 enca 来查看,file 命令可能不准确
enca 教程:https://blog.csdn.net/lovechris00/article/details/146443005


iconv 更多用法

$ iconv --help                                                                                                                  
iconv: unrecognized option `--help'
Usage:	iconv [-cs] -f <from_code> -t <to_code> [file ...]
	iconv -f <from_code> [-cs] [-t <to_code>] [file ...]
	iconv -t <to_code> [-cs] [-f <from_code>] [file ...]
	iconv -l

ICONV(1)                                                                                   General Commands Manual                                                                                  ICONV(1)

NAME
     iconv – codeset conversion utility

SYNOPSIS
     iconv [-cs] -f from_name -t to_name [file ...]
     iconv -f from_name [-cs] [-t to_name] [file ...]
     iconv -t to_name [-cs] [-f from_name] [file ...]
     iconv -l

DESCRIPTION
     The iconv utility converts the codeset of file (or from standard input if no file is specified) from codeset from_name to codeset to_name and outputs the converted text on standard output.

     The following options are available:

     -c    Prevent output of any invalid characters.  By default, iconv outputs an “invalid character” specified by the to_name codeset when it encounts a character which is valid in the from_name codeset
           but does not have a corresponding character in the to_name codeset.

     -f    Specifies the source codeset name as from_name.

     -l    Lists available codeset names.  Note that not all combinations of from_name and to_name are valid.

     -s    Silent.  By default, iconv outputs the number of “invalid characters” to standard error if they exist.  This option prevents this behaviour.

     -t    Specifies the destination codeset name as to_name.

EXIT STATUS
     The iconv utility exits 0 on success, and >0 if an error occurs.

EXAMPLES
     Convert file.txt from IBM273 to UTF-8 and save the result to converted.txt:

           iconv -f IBM273 -t UTF-8 file.txt > converted.txt

SEE ALSO
     mkcsmapper(1), mkesdb(1), iconv(3)

STANDARDS
     iconv conform to IEEE Std 1003.1-2008 (“POSIX.1”).

HISTORY
     iconv first appeared in NetBSD 2.0, and made its appearance in FreeBSD 9.0.

macOS 15.1                                                                                    October 22, 2009  

2025-03-22(六)

http://www.dtcms.com/a/84814.html

相关文章:

  • C#里使用libxl来对列或行进行分组显示
  • CTF题目 《FinalSQL》(极客大挑战 2019)WriteUp
  • idea接入 AI 编程助手:Copilot
  • KiLog2MaximumIncrement的由来和KiMaximumIncrementReciprocal的由来
  • 策略模式 vs. 工厂模式:对比与分析
  • 15:视图
  • T113-i开发板的休眠与RTC定时唤醒指南
  • git | 回退版本 并保存当前修改到stash,在进行整合。[git checkout | git stash 等方法 ]
  • 【安全运营】安全运营关于告警降噪的一些梳理
  • NO.55十六届蓝桥杯备战|排序|插入|选择|冒泡|堆|快速|归并(C++)
  • Linux-数据结构-双向链表与栈
  • Linux进程间通信方式
  • TypeScript教程
  • python爬虫可能遇到的小bug
  • 【RK3588嵌入式图形编程】-SDL2-渲染文本
  • CSS 文档流:元素排列的底层逻辑与布局控制
  • stm32-ADC
  • 明远智睿SD2351核心板:多接口融合,破解边缘计算难题
  • 关于强化学习小记
  • 玩转 SpringCloud - 快速构建分布式系统详解
  • 第十六届蓝桥杯康复训练--5
  • 排列与二进制
  • 力扣刷题记录-二叉树展开为链表
  • 【2025】基于springboot+vue的教务/课程/成绩管理系统设计与实现(源码、万字文档、图文修改、调试答疑)
  • Agent Team 多智能体系统解析
  • Python 魔术方法深度解析:__getattr__ 与 __getattribute__
  • Springboot之RequestContextHolder 学习笔记
  • CANFD芯片在辐射环境中的技术演进
  • 【数学建模】最大最小值模型详解
  • Spring的基本用法