以下AWK代码有什么作用?
awk 'OFS="\t" {$1=$1}1' /filepath
答案 0 :(得分:1)
它将<html>
<body style="background-color: blue;">
<div style="background-color: white; width: auto; max-width: 700px;
margin-left: auto; margin-right:auto; padding:30px">
<p>This is some text but the problem is that its doing something strange when I resize the width of the window, and it is very, very annoying.</p>
</div>
</body>
</html>
分配为制表符,然后检查OFS的值是否为0或null以外的值(因为您刚刚将其设置为制表符),如果是,则将其赋值通过使$ 0重新编译,将FS值替换为OFS值,从而使$ 1自身出现。由于FS是单个空白字符的默认值,这意味着将删除所有前导/尾随空白,并将所有其他连续的空白链替换为单个制表符。然后,它评估条件OFS
,发现条件为true,因此执行打印当前记录的默认操作。
答案 1 :(得分:0)
这样做(通过标签替换空格):
OFS="\t" # set output separator as a tab
{$1=$1} # remove extra spaces and set OFS as tab
1 # with awk, true, so print the current line