可以用awk去除前导空格和尾随空行

时间:2018-03-08 18:52:32

标签: unix awk

我有一个输出文件TorrentInfo{Created By: null Main tracker: http://torrent.ubuntu.com:6969/announce Comment: Ubuntu CD releases.ubuntu.com Info_hash: f07e0b0584745b7bcb35e98097488d34e68623d0 Name: ubuntu-17.10.1-desktop-amd64.iso Piece Length: 524288 Pieces: 2866 Total Size: 1502576640 Is Single File Torrent: true File List: Tracker List: http://torrent.ubuntu.com:6969/announce http://ipv6.torrent.ubuntu.com:6969/announce ,如下所示:(每行前导空格)和尾随空行。

file.out:

file.out

到目前为止,我能够做到这一点 - abc def ghi jkl *whitespace* 来修剪领先空间。

awk '{$1=$1};1' file.out可以删除空行/空格吗?

1 个答案:

答案 0 :(得分:1)

在输出行之前,只需更改当前逻辑以测试字段:

NF { $1 = $1; print }