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

one line awk 2

Status
Not open for further replies.

mdarsot

Instructor
Apr 13, 2006
86
CA
I have 48 files that i want to rename.

current filenames are
12345.zip
12346.zip
etc

New name should be
acx001.zip
acx002.zip
etc

How can i write one line awk statement to do incrementation of numbers. I have following code so far.

ls * | awk '{print "mv "$1," acx001.dat"}' > tt.sh
i am doing above and then edition tt.sh to manually increment acx001 to acx048. Is there a way to automate this.

please help

Thanks
 
Thanks

That worked great. If you dont mind can you please explain the one liner.

 
Hi

[tt]printf[/tt] - like the [tt]print[/tt] function, but with formating ( like the C [tt]printf[/tt] function, man 3 printf )
[tt] %s [/tt] - to be replaced with the next argument treated as string
[tt] %03d[/tt] - to be replaced with the next argument treated as decimal number, padded to length 3 with character "0"
[tt]++i [/tt] - preincrement the value of variable i and return the value

Feherke.
 
I used $0 instead of $1, thinking to possible spaces in the filenames
ls * | awk '{printf "mv [!]\"[/!]%s[!]\"[/!] acx%03d.dat\n",$0,++i}' > tt.sh

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top