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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -