LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   SED, AWK or PERL HELP (https://www.linuxquestions.org/questions/programming-9/sed-awk-or-perl-help-355026/)

embsupafly 08-19-2005 06:25 PM

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

carl.waldbieser 08-19-2005 07:30 PM

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.

Tinkster 08-19-2005 09:00 PM

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...

embsupafly 08-20-2005 01:58 AM

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.

Tinkster 08-20-2005 02:21 AM

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

embsupafly 08-20-2005 04:14 AM

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.

/bin/bash 08-20-2005 09:07 PM

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


All times are GMT -5. The time now is 08:25 AM.