Belajar Cosort 2

pas di `ls` kan keluar listing direktorinya or file, misal:

-bash-3.00$ ls *.txt
 note satu.txt
 note dua.txt
 note tiga.txt

kemudian di list dulu di satu file
-bash-3.00$ ls *.txt > listfile.txt

liat isi filenya
-bash-3.00$ more listfile.txt
 note satu.txt
 note dua.txt
 note tiga.txt

untuk merename nama file yang ada. (spasinya ilang)
-bash-3.00$ more listfile.txt | awk -F" " '{print "mv \""$0"\" \""$1$2"\""}'
 mv "note satu.txt" "notesatu.txt"
 mv "note dua.txt" "notedua.txt"
 mv "note tiga.txt" "notetiga.txt"

pastiin scriptnya bener (notasinya) trus masukin ke file script
-bash-3.00$ more listfile.txt | awk -F" " '{print "mv \""$0"\"\""$1$2"\""}' > rename.sh

-bash-3.00$ bash rename.sh

setelah di `ls` maka hasilnya
-bash-3.00$ ls
notesatu.txt
notedua.txt
notetiga.txt


0 komentar:

Posting Komentar