Created
January 16, 2014 06:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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