While loop doesn't stop (Bash) -
i want delete of blank lines , lines spaces (if exist (only bottom of file)) , remove 1 more line (also bottom of file).
i have code:
while [[ "$last_line" =~ ^$ ]] || [[ "$last_line" =~ ^[[:space:]]+$ ]] sed -i -e '${/$/d}' "./file.txt" done sed -i -e '${/$/d}' "./file.txt"
for reason loop doesn't stop , deletes in file. matter?
you can use tac
, awk
combination this:
tac file | awk 'begin{p=0} p<=1 && /^[[:blank:]]*$/{p=1; next} p==1{p++; next} 1' | tac tac file # prints files in reverse /^[[:blank:]]*$/ # find blank/empty lines using search pattern tac # reverse file content
Comments
Post a Comment