Home » Infrastructure » Unix » RENAMING A FILE
icon5.gif  RENAMING A FILE [message #292083] Mon, 07 January 2008 13:56 Go to next message
kham2k
Messages: 34
Registered: May 2007
Member
Hello All

I would like to rename files. Let me example what I am trying to do.

I have files coming in daily;
testfile200803101_508400.ZIP.PGP
testfile200703005_879850.ZIP.PGP

These are example only. one thing is for sure that it will start with "testfile" and ends with ".ZIP.PGP"

I would like to rename each file to two different name e.g.
testfile200803101_508400 and
testfile200803101.ZIP

I have tried to use sed
outfile=$(echo $INBOUND/$FILE_NAME | sed s/\.pgp/\.zip/)

where FILE_NAME=testfile*.PGP
but this will only replace pgp with zip

Thanks for your help
Re: RENAMING A FILE [message #292086 is a reply to message #292083] Mon, 07 January 2008 14:05 Go to previous messageGo to next message
Michel Cadot
Messages: 68722
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
This an Oracle forum not a Unix one.
Please post this in a Unix forum.

Regards
Michel
Re: RENAMING A FILE [message #293053 is a reply to message #292083] Thu, 10 January 2008 13:51 Go to previous messageGo to next message
Frank Naude
Messages: 4581
Registered: April 1998
Senior Member
Try something like this:

#!/bin/ksh

FILE_NAME=testfile200803101_508400.ZIP.PGP
echo "INPUT FILE = $FILE_NAME"

OUTFILE1=$(echo $FILE_NAME | sed "s/\.ZIP\.PGP//")
echo "OUTPUT FILE 1 = $OUTFILE1"

OUTFILE2=$(echo $FILE_NAME | sed "s/testfile\([0-9]*\)_\([0-9]*\)\.ZIP\.PGP/testfile\1.ZIP/")
echo "OUTPUT FILE 2 = $OUTFILE2"

Re: RENAMING A FILE [message #293058 is a reply to message #292083] Thu, 10 January 2008 14:23 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
man basename
Previous Topic: Regarding crontab schedule
Next Topic: unix shell scripting in oracle
Goto Forum:
  


Current Time: Thu Dec 12 04:12:07 CST 2024