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.
我有超过 400,000 个字段,input.txt由空格分隔。例如0 2 1 1 1 2重复 400,000 次。
input.txt
0 2 1 1 1 2
我需要把它们放在一起021112。
021112
我怎么做?
有很多方法可以做到这一点,最简洁的方法是tr删除所有空格:
tr
tr -d ' ' < file > outfile
或者sed:
sed
sed -i 's/ //g' file
警告:sed解决方案会用更改覆盖原始文件。
由于您询问awk一般解决方案是设置空白OFS并强制重建,$1=$1但它并不像前两个解决方案那样优雅:
awk
OFS
$1=$1
awk '{$1=$1}1' OFS= file > outfile