使用awk来删除字节顺序标记 [英] Using awk to remove the Byte-order mark
本文介绍了使用awk来删除字节顺序标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人一个想法如何awk脚本(presumably一个班轮)移走BOM会是什么样子?
has anyone an idea how an awk script (presumably a one-liner) for removing a BOM would look like?
规格:
- 打印后,每行的第一个(
NR大于1
) - 第一行:如果用
#FE #FF
启动或#FF #FE
,除去那些并打印其余
- print every line after the first (
NR > 1
) - for the first line: If it starts with
#FE #FF
or#FF #FE
, remove those and print the rest
推荐答案
试试这个:
awk 'NR==1{sub(/^\xef\xbb\xbf/,"")}{print}' INFILE > OUTFILE
在第一条记录(行),删除BOM字符。打印每条记录。
On the first record (line), remove the BOM characters. Print every record.
或略短,使用知识,在awk中的默认动作是打印记录:
Or slightly shorter, using the knowledge that the default action in awk is to print the record:
awk 'NR==1{sub(/^\xef\xbb\xbf/,"")}1' INFILE > OUTFILE
1
是始终计算为真最短的条件,所以打印的每个记录。
1
is the shortest condition that always evaluates to true, so each record is printed.
享受!
这篇关于使用awk来删除字节顺序标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文