<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux etc. &#187; awk</title>
	<atom:link href="http://promberger.info/linux/category/awk/feed/" rel="self" type="application/rss+xml" />
	<link>http://promberger.info/linux</link>
	<description>my outsourced memory for your perusal</description>
	<lastBuildDate>Thu, 08 Sep 2011 11:06:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Removing duplicate lines from a file</title>
		<link>http://promberger.info/linux/2009/01/14/removing-duplicate-lines-from-a-file/</link>
		<comments>http://promberger.info/linux/2009/01/14/removing-duplicate-lines-from-a-file/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 17:54:57 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[awk]]></category>
		<category><![CDATA[Bash shell]]></category>
		<category><![CDATA[Code snippets]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/2009/01/14/removing-duplicate-lines-from-a-file/</guid>
		<description><![CDATA[Case-insensitive: { rm "$file" &#038;&#038; awk '!x[tolower($1)]++' > "$file"; } < "$file" Case-sensitive: { rm "$file" &#038;&#038; awk '!x[$1]++' > "$file"; } < "$file" Here's a shell script you could use, as it stands, only works for one file at a time: #!/bin/bash usage() { cat "$filename"; } < "$filename" else { rm "$filename" &#038;&#038; [...]]]></description>
			<content:encoded><![CDATA[<p>Case-insensitive:</p>
<pre>{ rm "$file" &#038;&#038; awk '!x[tolower($1)]++' > "$file"; } < "$file"</pre>
<p>Case-sensitive:</p>
<pre>{ rm "$file" &#038;&#038; awk '!x[$1]++' > "$file"; } < "$file"</pre>
<p>Here's a shell script you could use, as it stands, only works for one file at a time:</p>
<pre>
#!/bin/bash                                                                                  

usage()
{
cat << EOF                                                                                   

usage: $(basename $0) options filename                                                       

Removes duplicates from a file                                                               

OPTIONS:
   -h      Show this message
   -i      case insensitive
EOF
               }                                                                             

insensitive="no"                                                                             

while getopts "hi" option; do
    case $option in
        h)
            usage  ; exit 0
            ;;
        i)
            insensitive="yes"
            ;;
        "")
            usage ; exit 1
            ;;
        *)
            usage  ; exit 1
            ;;
    esac
done                                                                                         

shift $(($OPTIND - 1))                                                                       

filename="$1"                                                                                

if [ "$filename" == "" ] ; then
    usage ; exit 1
elif [ ! -f "$filename" ] ; then
    echo "File $filename does not exist" ; exit 1
fi                                                                                           

# make a backup
cp "$filename" "$filename"~                                                                  

if [ $insensitive == "yes" ] ; then
    { rm "$filename" &#038;&#038; awk '!x[tolower($1)]++' > "$filename"; } < "$filename"
else
    { rm "$filename" &#038;&#038; awk '!x[$1]++' > "$filename"; } < "$filename"
fi
</pre>
<p>Here's some nice concise <a href="http://www.linux.com/feature/118031">information about getopts and shift</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2009/01/14/removing-duplicate-lines-from-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

