View Single Post
Old January 17th, 2013, 08:03 PM   #6 (permalink)
9to5cynic
Senior Member
 
9to5cynic's Avatar
 
Join Date: Feb 2011
Location: /home/
Posts: 4,858
 
Device(s): Galaxy S3 (Verizon) Evo 4G - retired/rooted
Carrier: Verizon

Thanks: 3,066
Thanked 1,762 Times in 1,189 Posts
Send a message via AIM to 9to5cynic
Default

Quote:
Originally Posted by MoodyBlues View Post
[high]#!/bin/bash

ls > /tmp/current_files
mv /tmp/current_files ./current_files
cat current_files | tr ' ' '_' > current_files_new
FileCount=$(wc -l current_files | awk '{print $1}')
count=1
while [ "$count" -le "$FileCount" ]
do ReadAwk="FNR=="$count
OldName=$(awk $ReadAwk current_files)
NewName=$(awk $ReadAwk current_files_new)
mv "$OldName" "$NewName" > /dev/null 2>&1
count=$(($count+1))
done
rm current_files
rm current_files_new
exit 0[/high]
I'm a bit of a scripting newb, but can I try to decipher this and see if I'm right?
I'll do comments below for visibility...

Code:
ls > /tmp/current_files
mv /tmp/current_files ./current_files 
#makes file consisting of this directories 
#contents (after moving it from /tmp)
cat current_files | tr ' ' '_' > current_files_new 
#actually does the 'replacing' and creates a
# new file for the underscore'd version....
FileCount=$(wc -l current_files | awk '{print $1}') 
#number of lines in original file... not sure what 
#awk is doing... that's the first argument right ($1) ??
count=1  
#looks like this whole part is just moving the original 
#file to the underscored file one at a time.... I like this part a lot :)
while   [ "$count" -le "$FileCount" ]
do 	ReadAwk="FNR=="$count  
#??? No clue what's happening here Setting FNR 
#to the current count level, but I don't know what FNR is?
	OldName=$(awk $ReadAwk current_files)
	NewName=$(awk $ReadAwk current_files_new)
	mv "$OldName" "$NewName" > /dev/null 2>&1
	count=$(($count+1))
done
# removes files created.
rm current_files
rm current_files_new
exit 0[/
9to5cynic is offline  
Reply With Quote