biolocal:ShellFileEditing
From Wiki CEINGE
Every command described here can be easily obtained in a high level scripting language (php). The use of bash is preferrable when you can't or won't set up an entire programming environement to launch simple commands against a list of text files.
Delete last line from a file/s
To obtain a text of a file without last line, just execute:
cuttedfile=`sed '$d' filename`;
Now you just need to write the new text in the same file:
echo "$cuttedfile">filename;
If you want to execute the same operation on a list of files contained in the same directory:
for filename in `ls`; \ do \ cuttedfile=`sed '$d' $filename`; \ echo "$cuttedfile">$filename; \ done;
Please, pay attention to the double quotes used to echo the $cuttedfile variable; they are needed to ensure the content of the text file is entirely kept (carrige returns, tabs and so on).