这能用awk实现吗?我希望添加一个新列,它分隔了现有列中的数据。我的输入文件是一个标签分隔的文本文件。设备-0,设备-1的列是从phone-0-1,phone-1-2派生的新列.
输入:
category1 phone-0-1 working 0000 0000 new 0
category1 phone-1-2 working 0000 0000 new 0
category1 phone-2-4 working 0000 0000 new 0
category1 phone-3-5 working 0000 0000 new 0
category1 phone-4-6 working 0000 0000 new 0输出:
category1 device-0 phone-0-1 working 0000 0000 new 0
category1 device-1 phone-1-2 working 0000 0000 new 0
category1 device-2 phone-2-4 working 0000 0000 new 0
category1 device-3 phone-3-5 working 0000 0000 new 0
category1 device-4 phone-4-6 working 0000 0000 new 0发布于 2013-08-17 22:38:57
试试下面的sed行,看看它是否有效:
sed 's/\sphone-[0-9]\+/&\t&/' fileawk也有同样的想法:
awk -F'\t' -v OFS='\t' '{sub(/phone-[0-9]+/,"&\t&",$2)}7' file编辑,重命名为设备:
sed 's/\(\s\+\)phone-\([0-9]\+\)/\1device-\2&/' filehttps://stackoverflow.com/questions/18293863
复制相似问题