Dos2Unix

Data Mining
CS 510 (DM)
Winter,2004
home | news | site map
review | project | subject | group
weka | mining | gawk | bash
modeling | reference | pods
Display: big | small

Why all the scripting?
 copyleft() {
        cat<<-EOF
        dos2unix: convert dos file format to unix
        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
  }

[TOP]


Motivation

Those of us doomed to work in both the Unix and Windows world have many times encountered files that were create/editted on systems other that the one we are on at the time of our edits. The symptom of this is the dreaded '^M' at the end of our Unix lines as seen in the example file file.dos:

 line1^M
 line2^M
 ^M

This tool changes <CR><LF> (DOS) to just <LF> (UNIX).

Most UNIX installations have a similar tool but this one optionally replaces the input file with the converted file.

[TOP]


Usage

 usage() {
        cat<<-EOF
        dos2unix  [FLAGs] FILE
        Convert from DOS to UNIX files
        Flags:
          -h        print this help text
          -l        copyright notice
          -r        replace the input file with the new file
          -x        run a demo
        EOF
        exit
 }

Installation

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/dos2unix.zip):

Standard files
config, and dos2unix.

Example files
file.dos

Third, make dos2unix executable:

 chmod +x dos2unix

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

[TOP]


Source code

Settings

Defaults:

 replace0=0

Paths:

 . config

Demo code

 demoDos2Unix() {
        cp file.dos file1.dos
        cp file.dos file2.dos
        replace=0
        main file1.dos > file1.unix
        replace=1
        main file2.dos
        cat<<-EOF
        Now call vi file.dos  file1.unix  file2.dos 
        file.dos SHOULD contain ^M (this is the file we started with)
        file1.unix SHOULD NOT
        file2.dos  SHOULD NOT
        EOF
        }

The Worker

 swap() {               
        $gawk '{sub(/\015$/,"") ;print $0}' $1
 }
 main() {
        if [ "$replace" -eq 1 ]
        then    swp=${temp}.swp
                swap $1 > $swp
                mv $swp $1
        else    swap $1
        fi
 }

Command-line processing

 demo=""
 while getopts "hlrx" flag
 do case "$flag" in
        l)  copyleft; exit;;
        h)  usage; exit;;
        r)  replace=1;;
        x)  demo="demoDos2Unix";;
    esac
 done
 shift $(($OPTIND - 1))
 replace=${replace:=$replace0}
 if [ -n "$demo" ]
 then $demo
      exit
 else main $1
 fi

[TOP]


Credits

Author

Tim Menzies , tim@menzies.us, http://menzies.us

Software

This page generated by Site: see http://www.cs.pdx.edu/~timm/dm/site.html

Acknowledgements

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/

[TOP]


Legal

Copyright

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.

Disclaimer

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.

[TOP]