Shell Script Which Will Discards All But One of Successive Identical

in Categories Academic, File-management last updated October 20, 2008
#!/bin/bash
# Write the shell program unique, which will discards all but one of successive
# identical 
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2005 nixCraft project.
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
echo -n "Enter file name : "
read file
 
if [ ! -f $file ]
then 
	echo "Not a file"
	exit 1
fi
 
uniq $file

Share this on:

1 comment

  1. Is this supposed to teach me about read, uniq or the test command? What s the advantage of creating this script, making it executable and running it instead of just doing uniq ? Why not just read the uniq man page?

    You didn’t really _write_ anything if you use the uniq program in the script.

    Have a question? Post it on our forum!