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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File - Limitiation???

Status
Not open for further replies.

Panthaur

IS-IT--Management
Jul 26, 2002
78
US
I have a relatively simple script which looks at a directory for all files that have an extension of .webctl, which is an ftp script to send a file of the same name but the extension of .txt to another computer. I have pasted the script below...

for i in `ls /tmp/orderout/*.webctl`
do
/usr/bin/ftp -vn < $i > /dev/null 2>&1;
/bin/mv $i /tmp/orderout/sent
done

Here is an example directory listing:

file1.webctl
file1.txt
file2.webctl
file2.txt
file3.webctl
file3.txt

And so on...

My problem is that after the ftp command finishes, I need to move both the .webctl AND the .txt file to the sent directory. My question is this, how do I extract just the first part of the file, (file1, file2, file3 in the examples above) and append .txt to it so that I can move that file as well as the .webctl file? Is there some sort of split command that I can use, or perhaps I need to use perl?

Any help would be MOST appreciated!

Thanks,
Panthaur


 
Hi,

Untested but try this ( I think I understand what you're asking )...

for i in `ls /tmp/orderout/*.webctl`
do
/usr/bin/ftp -vn < $i > /dev/null 2>&1;
/bin/mv $i /tmp/orderout/sent
txtfile=`echo $i | awk -F. '{print $1}'`
/bin/mv ${txtfile}.txt /tmp/orderout.sent
done

Matt.
 
Code:
txtfile=`basename $i .webctl`
mv $txtfile /tmp/orderout/sent
 
Bleh - forgot the suffix
Code:
mv ${txtfile}.txt /tmp/orderout/sent
 
No need to use awk or basename...

/bin/mv ${i%.webctl}.txt /tmp/orderout/sent
 
Doesn't that depend on which shell you have Ygor?
 
ksh has been around for fifteen years now, so it ain't exactly cutting-edge. Incidentally, my version of basename removes the file path as well as the txt extension, so it fails unless the current dir happens to be /tmp/orderout.
 
The variable expansion ${var%ext_pattern}.new_extension works fine also in bash and I think this is supported by most of shells
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top