LinuxQuestions.org
Help answer threads with 0 replies.
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 01-31-2012, 04:51 AM   #1
vadslogin
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
Rename files using script


Hi,
I'm bit new to linux & scripting.

Can anyone help me renaming the file with the script.

Say I've one file abc.txt
When I run the script it should automatically rename it to abc_new.txt

Thanks in advance.
 
Old 01-31-2012, 04:59 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
What have you tried so far?

How does the script know the abc.txt file name?
 
Old 01-31-2012, 05:02 AM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 619

Rep: Reputation: 42
we'll help, but we need to see you have made an effort to tackle your problem, especially since this seems like home work lol.Anyways show us what you started and we'll help.
 
Old 01-31-2012, 05:07 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
Edited so as to not undermine others replies...
 
Old 01-31-2012, 05:50 AM   #5
vadslogin
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Dear fukawi1,cbtshare,catkin,

Thanks for ur replies.

Im being automobile engineer, I hardly interact with linux, as I do most of the work in Windows.

Presently Im working on one Linux Automobile tool, during processing of some files I stuckup in automating them.

Using available basic commnands I tried to solve the problem. The problem was to combine different files into one (used "cat"), next step is to rename newly created fle with one of available files with "underscore"

As I've to manually rename those files I thought I can get any quick solution from forum, as it was bit urgent.

Say in one folder I've a.txt b.txt & c.txt
Im clubbing them to one using: cat a.txt b.txt c.txt > d.txt
Now I want to rename newly created file d.txt to first file (from chronological order) a.txt i.e mv d.txt > a_1.txt

Say in next diectory I've e.txt f.txt g.txt
My actions will be:
cat e.txt f.txt g.txt > d.txt
mv d.txt e_1.txt

Mr/Mrs cbtshare u r absolutely right. I shud've tried myself something. Due to urgency I thought I can get some solution.
 
Old 01-31-2012, 06:06 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
Why cat the files to the temporary file in the first place?
Using your first example, why not cat directly, to a_1.txt?
[code]cat a.txt b.txt c.txt > a_1.txt[code]
 
Old 01-31-2012, 06:46 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
So the script could cd into the directory but how is it then to identify the set of files to work on? The pattern *.txt is no good (try echo *.txt to see what the shell expands the pattern to) because that would also match a_.txt and presumably you don't want to mess with that.

What you want to do is almost certainly achievable; the hard part will be specifying exactly what is to be done.
 
  


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
Trouble with making a bash script to read in different files and rename output files. rystke Linux - Software 1 05-07-2009 09:00 AM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-23-2008 12:25 AM
Rename files with script sharathkv25 Programming 14 06-25-2007 04:00 AM
Script to rename files nazs Programming 15 03-31-2007 03:12 PM
Script to Rename Many Files geeman2.0 Programming 3 04-05-2006 02:45 PM

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

All times are GMT -5. The time now is 02:20 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration