copyleft() {
cat<<-EOF
zapblanks: remove columns and rows that are all blank
Copyright (C) 2004 Tim Menzies
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
EOF
}
EXCEL spreadsheets laid out to look pretty often have completely empty columns and rows. This tool removes them.
usage() {
cat<<-EOF
Usage: zapblanks [FLAGs] FILE
remove columns and rows that are all blank
Flags:
-h print this help text
-l copyright notice
-s CHAR column separator; default=$Q$sep0$Q
-x run an example
EOF
exit
}
zapblanksDemo() {
main zapblankseg100.dat
}
First, if you have installed anything from this site before, save your config file to somewhere safe.
Second, copy the following files to your directory (from
either ~timm/public_html/dm or
http://www.cs.pdx.edu/~timm/dm or
from http://www.cs.pdx.edu/~timm/dm/zapblanks.zip):
Third, make zapblanks executable:
chmod +x zapblanks
Fourth, compare your safe version of config
with the new version you just copied and fix up any paths.
Five, edit this file and config.
The first line of this file should point to your local bash shell.
and you'll need to check at least the #paths section in config
Check that all it works:
zapblanks -x
If the installation worked, then you should see a file with no empty columns or rows.
Defaults:
sep0=","
Paths:
. config
Minor details:
Q="\""
BEGIN {FS=OFS=","
}
This is a two pass system. Pass1, we look at all lines and find columns that are always empty.
FNR==1 {barph("pass " pass)}
Regardless of the pass, if a row is all blank, don't print it.
blankline() {barph("skipping " FNR); next;}
function blankline( i) {
if ($0 ~ White ) return 1;
for(i=1;i<=NF;i++) if (! ($i ~ White)) return 0;
return 1;
}
Count how many times a column has blanks.
pass==1 { Rows++;
for(I=1; I<=NF; I++) if ($I ~ White) Blank[I]++;
}
In pass 2, if a column is always blank, don't print it.
pass==2 { Str=""; Sep ="";
for(I=1; I<=NF; I++) {
if (Blank[I]==Rows) continue;
Str=Str Sep $I;
Sep=OFS;
};
if (Str) print Str;
}
main() {
$gawk -f lib.awk -f zapblanks.awk pass=1 $1 pass=2 $1
}
demo=""
while getopts "hls:x" flag
do case "$flag" in
h) usage; exit ;;
l) copyleft; exit;;
s) sep=$OPTARG;;
x) demo="zapblanksDemo";;
esac
done
shift $(($OPTIND - 1))
sep=${sep:=$sep0}
if [ -n "$demo" ]
then $demo
exit
else main $1
fi
Tim Menzies ,
tim@menzies.us,
http://menzies.us
This page generated by Site:
see http://www.cs.pdx.edu/~timm/dm/site.html
This site is built using PerlPod.Style sheet switching method taken from Eddie Traversa's excellent and simple-to-apply tutorial: http://dhtmlnirvana.com/content/styleswitch/styleswitch1.html.
Search engine powered by ATOMZ http://www.atomz.com/search/. Note, the indexes to this site are only updated weekly (heh, its a free service- what more ja want?).
Icons on this site come from http://www.sql-news.de/rubriken/olap.asp and http://www.ifnet.it/webif/centrodi/eng/toolbar.htm.
The JAVA machine learners used at this site come from the extensive data mining libraries found in the University of Waikato's Environment for Knowledge Analysis (the WEKA) http://www.cs.waikato.ac.nz/ml/weka/
Copyright (C) Tim Menzies 2004
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2; see http://www.gnu.org/copyleft/gpl.html. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
The content from or through this web page are provided 'as is' and the author makes no warranties or representations regarding the accuracy or completeness of the information. Your use of this web page and information is at your own risk. You assume full responsibility and risk of loss resulting from the use of this web page or information. If your use of materials from this page results in the need for servicing, repair or correction of equipment, you assume any costs thereof. Follow all external links at your own risk and liability.