Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些带有不同列号的制表符分隔的数据文件。我想为这些文件添加一个标题行,标题行仅在第一列中包含“ID”,但是标题行的总列号应该与文件相同。我可以用一些linux命令吗?非常感谢你!!
for file in * do awk 'NR==1{hdr=$0; gsub(/[^\t]/,"",hdr); print "ID" hdr}1' "$file" > tmp && mv tmp "$file" done
sed -i '1 { h; s/[^\t]//g; s/^/ID/; p; g; }' *.tsv
复制第一行,删除所有非标签(以清除字段内容),添加“ID”,然后打印此行加上原件。