Need help in scripting

Hi,

We have a requirement,client will post the file into ftp server with name as "prior-product-purchaseproductpurchase001_20150608.txt".One copy should be in this FTP server. After that we need to eliminate some part of the string in the filename "prior-product-purchase" and post the filename as this "productpurchase001_20150608.txt".

Thx in aadvance

HI,

client is dropping a file in daily basis e.g., "prior-product-purchaseproductpurchase001_20150608.txt" and need to eliminate some part of the string in filename and make it as "productpurchase001_20150608.txt".

Could you please help me in advance. How to achieve this.

Thx

Hello lkeswar,

If file's format will be always prior-product-*_date.txt , then following may help you in same.

 for i in prior-product-*
 do
     echo ${i##*-}
 done
 

Let me know if you have any queries on same.

Thanks,
R. Singh

The problem is the usual one, how to handle the file if you catch it during upload.

Can the client move the file after upload? Something like

PUT prior-product-purchaseproductpurchase001_20150608.txt /path/to/somewhereelse/prior-product-purchaseproductpurchase001_20150608.txt

RENAME /path/to/somewhereelse/prior-product-purchaseproductpurchase001_20150608.txt /destination/folder/prior-product-purchaseproductpurchase001_20150608.txt

That way, files will always appear in /destination/folder whole and complete, and you can just run this occasionally:

for FILE in /destination/folder/prior-*
do
        mv "$FILE" "${FILE/prior-product-purchase/}"
done
Moderator comments were removed during original forum migration.

Hi Ravinder,

filename=prior-product-purchaseproductpurchase001_20150608.txt
echo ${filename##*-}

output it is displaying : purchaseproductpurchase001_20150608.txt

but we need output should be

productpurchase001_20150608.txt

thx in advance

Hello lkeswar,

Following may help you in same.

 for i in prior-product-*
do
     echo ${i#*purchase}
done
 

Hope this helps.

Thanks,
R. Singh

1 Like