linux - 使用 awk 或 sed 打印从第 n 到最后的所有列

标签 linux unix awk sed gawk

这不是 another question 的重复项。 之前在 stackoverflow 上发布的所有问题/解决方案都有相同的问题:额外的空格被替换为单个空格。

示例(1.txt)

filename Nospaces
filename One space
filename Two  spaces
filename Three   spaces

结果:

awk '{$1="";$0=$0;$1=$1}1' 1.txt
One space
Two spaces
Three spaces

awk '{$1=""; print substr($0,2)}' 1.txt
One space
Two spaces
Three spaces

最佳答案

使用 -F 选项指定 IFS 以避免 awk 省略多个空格

awk -F "[ ]" '{$1="";$0=$0;$1=$1}1' 1.txt
awk -F "[ ]" '{$1=""; print substr($0,2)}' 1.txt

关于linux - 使用 awk 或 sed 打印从第 n 到最后的所有列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36307566/

相关文章:

linux - 将分隔字段移动到换行符

linux - 使用 awk 左外连接基于多列的两个 csv 文件,同时保持第一个文件观察的顺序

c++ - Shell 附加重定向替换现有文本?

linux - FFMPEG rtsp流向输出文件添加时间戳

regex - sed/perl 带有特殊字符 (@)

linux - 将文本输出存储在变量中 (bash)

linux - 将信息保存为一系列管道中间的变量

windows - 如何获取非常不寻常的格式文本文件的必要值?

Linux 哈希值

linux - 如何在 Linux 中设置 Java 类路径?