Skip to content

Instantly share code, notes, and snippets.

@konglie
Created January 16, 2014 06:50
Show Gist options
  • Save konglie/8450817 to your computer and use it in GitHub Desktop.
Save konglie/8450817 to your computer and use it in GitHub Desktop.
Script sederhana untuk menggabungkan seluruh file text dari berbagai jenis ekstensi file dalam satu folder menjadi 1 file.
#!/bin/bash
# Copyright Konglie (lee@konglie.web.id)
# Script sederhana untuk menggabungkan seluruh file text dari berbagai jenis ekstensi file
# dalam satu folder menjadi 1 file.
#
# Cara penggunaaan
# nama_script folder_yang_ingin_diolah
#
# Contoh
# ./myscript MyProgramFolder
# Lokasi file tujuan
DEST="/tmp/seluruh_script.txt";
# File Tujuan akan di-truncate, alias dikosongi.
> $DEST;
function doScan(){
ls -a $1 | while read f; do
if [ "$f" = "." -o "$f" = ".." ]; then
continue;
fi;
if [ -d "$1/$f" ]; then
doScan "$1/$f";
continue;
fi;
# script ini hanya memproses file text saja, file gambar atau binary lain tidak diikutsertakan
if file -bi "$1/$f" | grep -iq "text"; then
echo "Memproses file $1/$f";
echo "File $1/$f" >> $DEST;
cat "$1/$f" >> $DEST;
echo "" >> $DEST;
echo "" >> $DEST;
fi;
done;
}
doScan $1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment