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!

Rename Filename Error

Status
Not open for further replies.

dayankoven

Programmer
Oct 28, 2002
17
MY
Hi there fellow experts,

I'm trying to replace a filename from a working directory to a a new filename. The problem that i face is that 2 of the files share the almost the same filename. Both these files will reside at the same time in the same directory;
/home/working

For eg :-
File A = LOAN_APPL20031209122345
File B = LOAN_APPL_STATUS20031109122355

I need to rename File A to become 110020031209122345
and File B to become 120020031109122355.

The script that i have is as following :-

for file in $1*
do
echo ${file#$1$3}
mv "${file}" "$2${file#$1$3}"
done

$1 is the parameter passed in which would be LOAN_APPL for File A and LOAN_APPL_STATUS for File B.

The problem is that since it is $1*, file B is also getting renamed when it reality it should not be. Could someone please help show how i can rename only file A and leave file B intact.

Thanks in advance to all the experts.

 
One way - there'll be others :-
If LOAN_APPL is being passed in $1, and the datetimestamp is always 14 chars, then do
for file in $1??????????????

and for the other file :
for file in $1_S*


HTH


Dickie Bird (:)-)))
 
#!/usr/bin/ksh


FileA=LOAN_APPL20031209122345
FileB=LOAN_APPL_STATUS20031109122355

mv $FileA ${FileA##+([A-Z_])}
mv $FileB ${FileB##+([A-Z_])}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top