Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changeable filename

Status
Not open for further replies.

darfader

Programmer
Aug 6, 2003
38
GB

Hi,

I have been using the following to move a file from Unix to Windows

-- before
#! /bin/ksh

# Move to appropriate directory
cd /user/transfers/out/in_cab
mv unprocessed/*.* .
mv journey_tester.xml journey_tester.txt

# FTP all files in directory
ftp -inv server_name <<EOF
user username password
ascii
cd ESIFileIn
del journey_tester.xml
mput journey_tester.txt
rename journey_tester.txt journey_tester.xml
bye
EOF

mv *.* processed/


Now that it's working with a static filename, I have to get it working with a dynamically created filename. The following doesn't work

-- after
#! /bin/ksh

# Move to appropriate directory
cd /user/transfers/out/in_cab
mv unprocessed/*.* .
mv *.xml *.txt

# FTP all files in directory
ftp -inv server_name <<EOF
user username password
ascii
cd ESIFileIn
del *.xml
mput *.txt
rename *.txt *.xml
bye
EOF

mv *.* processed/


The filename will be similar to this....

JourneyScheduleImport1009207604061601_20040616022915.xml

but will change constantly.

How can I cope with this situation please ?


tia,
 
mv *.xml *.txt
will not work.
You have to move the files one by one;
a loop would help.
 
mv *.xml *.txt

I dont think that will work.
Try in its place:
Code:
for i in `ls | grep xml`
 do
  newname=`echo $i | awk -F\. '{print $1}'`
  mv $i $newname.txt
 done

this: mv *.* processed/
can be: mv * processed/


___________________________________
[morse]--... ...--[/morse], Eric.
 
Replace this:
mv *.xml *.txt
By this:
for f in $(ls *.xml); do mv $f $(basename $f xml)txt; done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
or:

for f in *.xml; do mv $f $(basename $f xml)txt; done

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi Vlad.
What happens when NO xml file ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You would get a error message...
[tt]
mv: *.xml: cannot access: No such file or directory
[/tt]
...and the return code is set. Both of which are useful actions because the rest of script would try to send files which do not exist.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top