LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-19-2005, 06:25 PM   #1
embsupafly
Member
 
Registered: Nov 2002
Location: ARIZONA
Distribution: Ubuntu
Posts: 44

Rep: Reputation: 15
SED, AWK or PERL HELP


I have files with entries like this:

Yamaha__4
.EPS
Yamaha__5
.EPS
Yamaha__6
.EPS
Yamaha__7
.EPS
Yamaha__8
.EPS
Yamaha__9
.EPS
York_
.EPS
York__2
.EPS
York__3
.EPS


I need to have the .EPS to be on the previous line with the file name:

so Yamaha__4
.EPS

Would become

Yamaha__4.EPS


I think it has something to do with a newline feature, any suggestions on how to go through a few files and fix this?

Thanks,

Eric
 
Old 08-19-2005, 07:30 PM   #2
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
How about
Code:
$ grep -v ".EPS" your-file | awk '{printf("%s.EPS",$0);} > newfile'
Grabs every line in the file that isn't ".EPS", then writes out that line with the .EPS extension.
 
Old 08-19-2005, 09:00 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Code:
sed -i -e'/EPS/ d' -e's/$/\.eps/g'  <yourfile>
Cheers,
Tink


P.S.: One question: looking at
http://www.linuxquestions.org/questi...der=descending
I have that suspicion this all might be homework
stuff? You seem to have an awful lot of weird
files that need conversion...

Last edited by Tinkster; 08-19-2005 at 09:06 PM.
 
Old 08-20-2005, 01:58 AM   #4
embsupafly
Member
 
Registered: Nov 2002
Location: ARIZONA
Distribution: Ubuntu
Posts: 44

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Tinkster


P.S.: One question: looking at
http://www.linuxquestions.org/questi...der=descending
I have that suspicion this all might be homework
stuff? You seem to have an awful lot of weird
files that need conversion... [/B]
No we have a client that needs to rename 17,000 files that used to be 000001.eps, 000002.eps up to 17,000 and the want to rename them according to the name that the .eps file is (which happens to be corporate logos). We just needed to find a way to rename them all using two text files, one with the original file names, and one with the proposed file names along with the original logos, all named 000001.eps and so forth. That way it is easier for them to find their desired logo more quickly. We so far have used Perl, Bash, Sed, and Awk in a series of steps to rename these for them. We received alot of help from the members of LQ and once we are done we would like to submit a tutorial of how to do this based on what we have done sucessfully all with open source tools.

It is important to note that the clients did spend one day trying to manually rename these files in Windows, it took one person 8 hours to rename 300 files. For them to rename these 17,000 files in this attempt, it would take almost 60 full 8 hour days, 480 man hours to do this task, $10 per hour would be $5,000; $20 per hour would be $10,000, we wanted to save them time and money and demonstrate the resourcefulness of Open Source products, needless to say they are very impressed.

Thanks.
 
Old 08-20-2005, 02:21 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Thanks for the explanation, it's just that I've answered
a few of your queries over the last few weeks, seen
others answer more, and you only ever come back
with different questions.


Btw, I'm sure that others would appreciate a "thanks",
and maybe some sort of feed-back whether their solutions
worked for you, too. You know, this place is driven
by volunteers, and to just come in and abuse us as
a free problem-solving machine, specially when you
get money for it (you did say "your customers", right?)
appears a bit rude.



Cheers,
Tink
 
Old 08-20-2005, 04:14 AM   #6
embsupafly
Member
 
Registered: Nov 2002
Location: ARIZONA
Distribution: Ubuntu
Posts: 44

Original Poster
Rep: Reputation: 15
You are right, I should express my thanks in the previous posts, I will remember to do that in the future. And to all members out there who have helped me in the past, I appreciate your time and support.

I just also wanted to mention, as I did in my last post, that once all of this is done and over with, I intended on providing a case study or tutorial on how to batch rename thousands of files to unique file names. Is this not a way to say thanks? Giving back to the community? This all sounds familiar somehow?

I don't think I am the rude one here, read your last post.

By the way I work for "The MAN", so I did not profit from it in any way other than the knowledge.

Last edited by embsupafly; 08-20-2005 at 04:18 AM.
 
Old 08-20-2005, 09:07 PM   #7
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
This code just joins every other line in a file to the previous line.
sed '$!N;s/\n//' filelist

Last edited by /bin/bash; 08-20-2005 at 09:09 PM.
 
  


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
Sed & Awk hinetvenkat Linux - Software 4 05-30-2005 05:10 AM
awk and sed issues alaios Linux - General 11 03-24-2005 05:33 AM
sed or awk help requested tonyfreeman Programming 7 10-03-2004 12:23 AM
awk/sed help pantera Programming 1 05-13-2004 11:59 PM
sed/awk problem player_2 Programming 9 08-26-2003 06:09 PM


All times are GMT -5. The time now is 07:26 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