LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2013, 10:46 AM   #1
Raury
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Rep: Reputation: Disabled
Wink File naming using awk


Hi,

I am a complete newbie.

how do I use awk to rename 950 files in a folder from s-xxx.txt to S-xxx.txt and from SU-xxx.txt to Su-xxx.txt where xx are numbers from 1 to 950.

Thanks
 
Old 03-25-2013, 11:02 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi and welcome to LinuxQuestions!

To rename files the rename command is more straightforward. Depending on your Linux distribution you may have one of two different flavours of the rename command. What Linux OS are you running on?

Or do you have some reasons to use awk instead?
 
Old 03-25-2013, 11:06 AM   #3
Raury
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Renaming file names

Hi,

I am not in linux at this moment as I am on my PC at home and going into linux from EXCEED. I have 950 files to rename. 560 are in one directory and the rest in another directory.

Thanks!

Raury
 
Old 03-25-2013, 11:08 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Why use awk?
Code:
for i in s-[0-9][0-9][0-9].txt do
   n= ${i:1}
   mv $i S${n}
done
for i in SU-[0-9][0-9][0-9].txt do
   n= ${i:2}
   mv $i Su${n}
done
 
1 members found this post helpful.
Old 03-25-2013, 11:10 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,520

Rep: Reputation: 7944Reputation: 7944Reputation: 7944Reputation: 7944Reputation: 7944Reputation: 7944Reputation: 7944Reputation: 7944Reputation: 7944Reputation: 7944Reputation: 7944
Quote:
Originally Posted by Raury View Post
Hi,
I am a complete newbie.

how do I use awk to rename 950 files in a folder from s-xxx.txt to S-xxx.txt and from SU-xxx.txt to Su-xxx.txt where xx are numbers from 1 to 950.
Thanks
You don't have to use awk...very first hit in Google for "rename multiple files in Linux":
http://www.cyberciti.biz/tips/renami...ll-prompt.html

The rename command will do what you need.
 
Old 03-26-2013, 01:59 AM   #6
nicksu
Member
 
Registered: Dec 2012
Posts: 35

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
Why use awk?
Code:
for i in s-[0-9][0-9][0-9].txt do
   n= ${i:1}
   mv $i S${n}
done
for i in SU-[0-9][0-9][0-9].txt do
   n= ${i:2}
   mv $i Su${n}
done
can use ${i#*s} and ${#*U} to replace the both n
 
Old 03-26-2013, 07:25 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by nicksu View Post
can use ${i#*s} and ${#*U} to replace the both n
Aw poo. I missed that one.
 
Old 03-26-2013, 08:14 AM   #8
Raury
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Rename

Thank you all - works!

Raury
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running series of awk commands from an awk file oreka18 Programming 3 05-16-2012 01:13 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 10:49 AM
[SOLVED] Sed/awk magic to change rpm naming convention dann_radkov Linux - Newbie 3 03-09-2012 10:21 AM
Is there a way to have grub translate its own naming to naming scheme under Linux zhjim Linux - Software 6 05-28-2006 08:09 AM
mail server the naming naming convention problem kashan Linux - Newbie 0 07-16-2004 02:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration