Showing posts with label join command UNIX shell sh bash linux. Show all posts
Showing posts with label join command UNIX shell sh bash linux. Show all posts

Friday, June 18, 2010

Recycle bin script


crm()
{
# pass this function the name of the directory that
# you want to backup and remove
if [ -d "$1" ]
then
cd "${1}/../"
else
echo "Directory does not exist"
return 1
fi

PWD=`pwd`
BKPFILES=`find $PWD -type -f`
BKPDIR="$HOME/.Trash"
daten=`date +%Y.%m.%d-%H.%M.%S`

for i in $BKPFILES
do
echo "$i"
DIRNAME="$BKPDIR"`echo ${i%/*}`
FILENAME=`echo ${i##*/}`
mkdir -p "$DIRNAME"
cp -pf "$i" "${DIRNAME}/${FILENAME}.${daten}"
#NEWFILE=`echo "$i" | sed 's|[ \/]|_|g'`
print "$i" "$NEWFILE" " $DIRNAME"
done
rm -rf "$1"
cd -
}

Wednesday, July 09, 2008

Join UNIX Command

Join takes two sorted text files and joins them together on common keys, similar to the Join SQL statements.

Basic join syntax:
join file1 file2

Specify a delimiter other than the default of whitespace (for input and output):
join -t: file1 file2 # sets the delimiter to be a colon


Join on specific columns in each file:
join -1 1 -2 1 file1 file2 # this will make file1's first column join with the file2's first column.

Join on a specific column and output specific columns:
join -11 -21 -o 1.1 1.2 2.1 2.2 file1 file2 # the -o options takes space-seperated arguments that take the form of file.column to specify only particular columns.

Specify filler text in a result column when two keys do not match between files:
join -e "none" file1 file2 -o 1.1 1.2 2.1 2.2 # the -e option needs to be used with -o

http://www.softpanorama.org/Tools/join.shtml
http://www.computerhope.com/unix/ujoin.htm