dos2unix bash script – part two

In this article I'll show you a more complex script than the script I have shown in the article dos2unix bash script. This new script allow you to convert more than one file at the same time.

Here is the script:

#!/bin/bash
###############################################################################
# dos to unix bash script                                                     #
# 2009 www.xAppSoftware.com                                                   #
# Luigi D'Andrea                                                              #
#-----------------------------------------------------------------------------#
# save this script, then chmod +x the script, the you are ready to run it     #
#-----------------------------------------------------------------------------#
# Licence:                                                                    #
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY #
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED   #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE      #
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY #
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  #
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;#
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND #
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  #
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF    #
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.           #
###############################################################################
case "$#" in
                0)      echo "Usage: `basename $0` <files_to_convert>";
                exit;;
esac

for f in "$@"
do
                echo $f
                cat $f | tr "\015" "\012" > $f.new
                mv  "$f.new"  "$f"
done

Posted by at May 9, 2009
Filed in category: Bash Tip & Tricks, linux, UNIX TLC, and tagged with: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

Statistical data collected by Statpress SEOlution (blogcraft).