【发布时间】:2017-08-09 05:57:32
【问题描述】:
如何删除文件末尾的空行?我尝试了sed 的多种组合,这是我目前的尝试。不使用awk可以去掉最后的空行吗?
printf "" > "temp.txt" #erases any current values in temp.txt
for num in "${myarr[@]}" #the value from the array was taken from a file with an empty line at the end as well
do
echo $num >> "temp.txt" #writes new values in new line
done
sed '/^$/d' "temp.txt"
它与建议的副本的不同之处在于我正在使用
for var in "${@:3}"
do
filename=${var}".txt"
cut -d ',' -f "$var" mycsv.csv > "$filename"
done
写入文件,因此我无法像在 while 循环中那样轻松控制写入文件的内容
【问题讨论】:
标签: bash file sed terminal line