LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-04-2006, 05:38 PM   #1
uprjamaja
LQ Newbie
 
Registered: Dec 2006
Location: Estonia
Posts: 5

Rep: Reputation: 0
Question AWK script: moving, copying and renaming files


I`ve got a task:

Directory contains files like this:
**********************************.abc

and file cache.txt, where are lines
**********************************=filename.txt
**********************************=filename.doc etc

I have to write AWK script, which would move/copy files according to their extension from given directory to required directory and give them correct names.

I`m really looking forward to getting some help.
Thank you very much for your time!
 
Old 12-04-2006, 06:17 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,991
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
I have to write AWK script
...so... what have you got so far? Please post anything.


which would move/copy files according to their extension
Example (in Bash though and should use find -print0 really)
Code:
find /some/dir -type f | while read f; do
 [ "${f/./}" != "${f}" ] && break
 ext="${f//*./}"; echo "mv ${f} /constant/dir/${ext}"
done

from given directory to required directory
Define "required"?


and give them correct names.
Define "correct"?
 
Old 12-04-2006, 06:23 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
a homework perchance?
 
Old 12-04-2006, 06:47 PM   #4
uprjamaja
LQ Newbie
 
Registered: Dec 2006
Location: Estonia
Posts: 5

Original Poster
Rep: Reputation: 0
unSpawn -> The problem is that I don`t even know, where to start from. I haven`t ever written scripts in AWK. It`s fair that i said it, isn`t it?
That`s why it would be great, if someone could help me just because he/she has a free time. I`d be really thankful to this person for explaining me how to write this.

matthewg42 -> something like that..

Anyway, thanks for answering.

P.S. At least thank you for helping me practising my English
 
Old 12-04-2006, 06:47 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,991
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
Yeah, that thought ocurred to me as well and thats why I said "...so... what have you got so far? Please post anything.". We'll see soon enough I guess.
 
Old 12-04-2006, 06:54 PM   #6
uprjamaja
LQ Newbie
 
Registered: Dec 2006
Location: Estonia
Posts: 5

Original Poster
Rep: Reputation: 0
unSpawn -> I understood it like this:
For example I have file 123.abc, in this case I should rename it to 123.txt. That means "correct".
Required directory means that I have a fixed directory where I should move correctly named files. For example C:\Correct.
Thank you for answering so quickly. I`m a newbie here, but it seems you`re nice moderator

Last edited by uprjamaja; 12-04-2006 at 06:57 PM.
 
Old 12-04-2006, 07:50 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,991
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
matthewg42 -> something like that..
Since this apparently concerns homework you won't like this.

The LQ Rules deny you asking for help with homework, especially overly broad, generic questions. What you *can* do is ask specific questions. Besides that if LQ would provide you with the answers it would be suspicious to say the least since it would appear you developed an advanced style of scripting overnight and you wouldn't learn from it (which homework basically is for even though you may think otherwise right now).


The problem is that I don`t even know, where to start from.
Read and practice. Here's some Awk tutorials to start with:
http://www.vectorsite.net/tsawk.html
http://sparky.rice.edu/~hartigan/awk.html
http://stud.wsi.edu.pl/~robert/awk/
http://www.grymoire.com/Unix/Awk.html
http://www.cs.hmc.edu/tech_docs/qref/awk.html
 
Old 12-04-2006, 08:11 PM   #8
uprjamaja
LQ Newbie
 
Registered: Dec 2006
Location: Estonia
Posts: 5

Original Poster
Rep: Reputation: 0
unSpawn -> If it was homework, I`d say it was homework, but it isn`t, that`s why I said "something like that". Logically, isn`t it?
By the way, thanks for the links!
 
Old 12-05-2006, 06:07 AM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,991
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
If it was homework, I`d say it was homework, but it isn`t, that`s why I said "something like that". Logically, isn`t it?
No actually it isn't. I'll forego explaining why, but if you can explain your "something like that", it could help us determine whether this is homework or not.
 
Old 12-05-2006, 12:58 PM   #10
uprjamaja
LQ Newbie
 
Registered: Dec 2006
Location: Estonia
Posts: 5

Original Poster
Rep: Reputation: 0
unSpawn -> It is not homework. I`ve got this task in one book, which I`m reading at the moment. And the problem is that book has completely different chapters, I mean it doesn`t explain how to use awk for moving or copying files, it only has the names of these commands and that`s all. The rest of the chapter explains how to search for files, rename them etc. Actually it`s written in Estonian, that`s why I forgot to define some words, while translating the task. It`s written there that this task is quite easy, that`s why they won`t explain how to do that. So I thought someone could help to understand. And that is the reason why I said "something like that". Because it`s my own homework
Anyway thanks.
 
Old 12-05-2006, 01:06 PM   #11
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
You can use system() to call mv, cp etc.
 
  


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
Script for renaming files auwolf Linux - Newbie 1 10-03-2006 02:39 AM
Renaming files in a shell script Mike_the_Man Programming 7 04-17-2006 01:56 PM
Another renaming files Perl script STAGED Programming 6 03-04-2006 05:07 AM
renaming files script. xushi Programming 4 10-10-2004 08:06 AM
errors while copying/moving files plisken Linux - General 14 06-07-2003 05:57 AM


All times are GMT -5. The time now is 04:56 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration