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!

I need help on renaming files using awk or sed please

Status
Not open for further replies.

HHG

Technical User
Nov 8, 2003
68
GB
I have a list of files with a file structure as below:-

07(year)+11(month)+19(day of the month)+24(hour)+10(minutes)+55(seconds)+afilenameanylength.txt


I need to rename the file so I get rid of the 07(year)+11(month)+19(day of the month)+24(hour)+10(minutes)+55(seconds) and rename it to afilenameanylength.txt
e.g ls *.txt | awk '{print "mv" $1, substr($1,13,25)}'

Can anyone help please, it will be most appreciated.

Many thanks in advance.
 
This?

Code:
ls *.txt | awk '{print "mv"[red],[/red] $1, substr[red]($1,13)[/red]}'[red]|sh[/red]

but it's kind of dangerous because you may end up overwriting a lot of files that once had a unique name...

Therefore, a trial run:
Code:
ls *.txt | awk '{print "[red]echo[/red] mv", $1, substr($1,13)}'|sh


HTH,

p5wizard
 
It's not quite what you asked ffor but..
Code:
#!/bin/ksh
for file in *.txt
do
  mv $file ${file##[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]}
done
But I'm sure someone will come up with a better version

Ceci n'est pas une signature
Columb Healy
 
thanks for this all.

I now get this

echo cp 000008522130127cl 000008522130127cl .csv

I need to get rid of the space between second file name and the .csv

any clues.

I used this syntaxls * | awk '{print "echo cp", $1, $1,".csv"}'> filename

so it reades:-

echo cp 000008522130127cl 000008522130127cl.csv


 
so, get rid of the last comma between $1 and ".csv" ...


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top