INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

I need help on renaming files using awk or sed please

I need help on renaming files using awk or sed please

I need help on renaming files using awk or sed please

(OP)
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.

RE: I need help on renaming files using awk or sed please

This?

CODE

ls *.txt | awk '{print "mv", $1, substr($1,13)}'|sh

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 "echo mv", $1, substr($1,13)}'|sh

HTH,

p5wizard

RE: I need help on renaming files using awk or sed please

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

RE: I need help on renaming files using awk or sed please

(OP)
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


RE: I need help on renaming files using awk or sed please

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

HTH,

p5wizard

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close