删除最后一个空白行 [英] Removing last blank line
问题描述
sed -i'/ ^ $ / d'combined.csv
但它不起作用,空行仍然存在。我可以使用以下命令删除最后一行。
sed -i'$ d'combined.csv
但是有可能在删除它之前检查最后一行是否真的空?
更新:
我使用以下命令检查每行是否以数字开头。
sed -i'1s / ^ [^ 0-9] * //'combined.csv
这仅检查第一行,而不检查其余行。我如何使它检查文件中的所有行?这可能会解决我的问题。
请尝试 $ {/ ^ $ / d;}
如果它是文件的最后一行,它将只匹配一个空行。
更新:对于第二个问题,只需在s之前删除1 ,即: sed -i's / ^ [^ 0-9] * //'combined.csv
There is a para break at the end of my .csv file. I tried to remove the blank line that is at the end of the file using the following command.
sed -i '/^$/d' combined.csv
But it does not work and a blank line is still there. I can remove the last line using the following command.
sed -i '$d' combined.csv
But is it possible to check if the last line is really empty before removing it?
Update:
I am using the following command to check if each line start with a number.
sed -i '1s/^[^0-9]*//' combined.csv
This checks only for the first line and not the rest of the lines. How do I make it check all the lines in the file? This might solve my problem.
Try ${/^$/d;}
this will only match an empty line if it is the last line of the file.
Update: for your second question, just remove the 1 before the s, i.e.: sed -i 's/^[^0-9]*//' combined.csv
这篇关于删除最后一个空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!