Wednesday, 11 July 2007

Shell: csd - cut sort duplicate

Below is simple script to cut the specified field ("|" separated) from flat file and display duplicate values.

###### Start Script #############
#!/bin/sh

if [ $# -lt 1 ]
then
echo "Usage: $0 <filed_number> <filename>"
exit;
fi

cut -d"|" -f$1 $2|sort |uniq -d

###### End Script ###############

How to run
copy the contents from start script to end script and place in a file named csd

$ chmod a+x csd
$ copy the csd to bin
$ csd 1,3 filename
523|523
e23|e23
r23|r23
t23|t23
y23|y23

No comments: