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

rename file

Status
Not open for further replies.

hammam02

IS-IT--Management
Mar 23, 2009
27
EG
i have programe to output report
name of report XXX
if i will process the same programe replace the report name
i need to mv XXX tp XXX_1 XXX_2 XXX_3

i tray to write script
COUNT= `expr $count + 1`
but i can't compleat
 
Hi

I would use a function like this :
Code:
[COLOR=darkgoldenrod]mkseqname()[/color]
{
  [COLOR=chocolate]local[/color] [navy]name[/navy][teal]=[/teal][green][i]"$1"[/i][/green] [navy]nr[/navy][teal]=[/teal][purple]1[/purple]
  [b]while[/b] [teal][[[/teal] -f [green][i]"${name}_$nr"[/i][/green] [teal]]];[/teal] [b]do[/b] [teal](([/teal] nr[teal]++[/teal] [teal]));[/teal] [b]done[/b]
  echo [green][i]"${name}_$nr"[/i][/green]
}
So the renaming would look like this :
Code:
mv [green][i]'XXX'[/i][/green] [green][i]"$( mkseqname 'XXX' )"[/i][/green]
Tested with [tt]bash[/tt] and [tt]mksh[/tt].

Feherke.
 
thank u
ok but in the first execute
when i execute again i found err
"nr++ : 0403-053 Expression is not complete; more tokens expected."

note

OS AIX 5.2
and i but ur progarame in script
 
[tt](( nr++ ))[/tt] is short for [tt](( nr=nr+1 ))[/tt]

But ksh doesn't understand [tt](( nr++ ))[/tt]
So just use the format [tt](( nr=nr+1 ))[/tt]

HTH,

p5wizard
 
THANK YOU VERRY MATCH

but the file XXX.lis after i mv it XXX.lis_1

i need to mv it like

XXX_1.lis
XXX_2.lis
XXX_3.lis
 
Hi

And why not mentioned it at the beginning ?
Code:
[COLOR=darkgoldenrod]mkseqname()[/color]
{
  [COLOR=chocolate]local[/color] [navy]name[/navy][teal]=[/teal][green][i]"${1%.*}"[/i][/green]
  [COLOR=chocolate]local[/color] [navy]ext[/navy][teal]=[/teal][green][i]"${1:${#name}}"[/i][/green] [navy]nr[/navy][teal]=[/teal][purple]1[/purple]
  [b]while[/b] [teal][[[/teal] -f [green][i]"${name}_$nr$ext"[/i][/green] [teal]]];[/teal] [b]do[/b] [teal](([/teal][navy]nr[/navy][teal]=[/teal]nr[teal]+[/teal][purple]1[/purple][teal]));[/teal] [b]done[/b]
  echo [green][i]"${name}_$nr$ext"[/i][/green]
}

Feherke.
 
Default shell in AIX (even in AIX61) is /usr/bin/ksh which is the old ksh88. The newer ksh93 is also available as /usr/bin/ksh93.

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top