If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > separating filenames

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-31-06, 08:39
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
Question separating filenames

I am trying to write a script that will take a list of filenames, operate on them individually and output a changed file name - mainly for renaming a large number of files.

So far I have

TARGET="$(ls -1 |)"

for FILE in "$TARGET"; do

NEW=$(echo "$FILE" | 'do some stuff to file')

mv $FILE $NEW

done

but all the filenames are kept as one long string in $FILE, and $NEW, so I can't do anything with them once I have changed them. How can I get the script to see each filename separately?
Thanks
Reply With Quote
  #2 (permalink)  
Old 03-31-06, 09:31
upsingh upsingh is offline
Registered User
 
Join Date: Aug 2004
Posts: 10
Quote:
Originally Posted by davidcollins001
I am trying to write a script that will take a list of filenames, operate on them individually and output a changed file name - mainly for renaming a large number of files.

So far I have

TARGET="$(ls -1 |)"

for FILE in "$TARGET"; do

NEW=$(echo "$FILE" | 'do some stuff to file')

mv $FILE $NEW

done

but all the filenames are kept as one long string in $FILE, and $NEW, so I can't do anything with them once I have changed them. How can I get the script to see each filename separately?
Thanks
**************************
for file in `ls -l|grep "^-"|awk '{print $9}'`
do
# do whatever u want to do on file
echo $file
#1st option
echo $file>${file}Newname
#2nd option
mv $file newfile
done
**********************
ur code seems correct except $NEW ,bcz if u allready defined NEW as a variable then it will alws take the constant value of that variable ..which is defined before the loop
Reply With Quote
  #3 (permalink)  
Old 03-31-06, 10:04
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool


Remove the double quotes in:

Code:
...
for FILE in $TARGET; do
...


__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #4 (permalink)  
Old 04-03-06, 04:11
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
thanks guys,

Don't the double quotes just maintain the format? So everything remains on separate lines instead of being placed on one?
Reply With Quote
  #5 (permalink)  
Old 04-03-06, 04:19
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
The double quotes will make it one parameter e.g.
#!/usr/bin/ksh
echo $1
echo $2
echo $3
# s1 "a b c" d e
a b c
d
e
# s1 a b c d e
a
b
c
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On