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.
我想在文件顶部添加一行,比如f1使用 awk。 有没有比以下更好的方法?
f1
awk 'BEGIN{print "word"};{print $0}' f1 > aux;cp aux f1;\rm aux<br/>
-iawk在 sed 中有类似选项吗?
-i
为什么不使用 sed - 它会使解决方案更直接
$sed -i.bak '1i\ word ' <filename>
另一种方法是:
sed -i '1s:^: Word1\nWord2 :' file