Solved

script to replace files names and text

Posted on 2001-07-18
9
161 Views
Last Modified: 2013-12-26
hi .

I have many files

each file begins with :

tg_BLA_BLA.pm

each file contain some text begins with tg_ or TG_

1. replace names tg_* > ft_*
2. replace text tg_* or TG_* > ft_* or FT_* accordingly .

Tal
0
Comment
Question by:Talmash
9 Comments
 
LVL 8

Expert Comment

by:mnashadka
ID: 6293609
Something like this would probably work for you:

#!/bin/ksh

for file in tg_*.pm
 do
  sed s/tg_/ft_/g $file | sed /TG_/FT_/g  "ft_"${file#tg_}
 done

Hope this helps.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 6294012
find . -name tg_\* -exec "perl -i -pe 's/tg_/ft_/g;s/TG_/FT_/g' {} ;echo {} XXXX {} \;"|sed -s 's#XXXX ./tg_#ft_/'|sh
0
 
LVL 84

Expert Comment

by:ozo
ID: 6294404
perl -i -pe 's/(tg_)/"ft_"^$1^lc($1)/ieg'
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 8

Expert Comment

by:mnashadka
ID: 6294446
I'm sorry, my line should be:
sed s/tg_/ft_/g $file | sed /TG_/FT_/g > "ft_"${file#tg_}

(missed the redirect operator).

ahoffman and ozo: why would you start up the whole perl interpreter for sed commands?  The perl interpreter is by far the fattest, most expensive interpreter (outside of Java).  I'm not attacking you; I'm just curious.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6294482
.. 'cause sed sucks in performance. Even a fat perl is faster in most cases ;-) and works identically on all supported platforms, and is much more comfortable in using regex, and .. and .. and ...
BTW, even (g)awk is faster than sed (at least on all Solaris and IRIX).

Talmash , sorry for off-topic comment.
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 6294669
ahoffman, doesn't that really depend upon what you're doing.  If your going through thousands of records, I would agree; but if you're talking about a couple of hundred records, then the invocation of the perl shell takes longer than the whole sed thing.  And you're still using sed in your answer.  Anyway, it doesn't matter, you just have to use the right tool for the job.  Sorry for the comment, and thanks for the info.

Talmash, I'm sorry for the off-topic comment as well.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6295540
mnashadka, I started using the right tools (like sed:) before Larry started programming perl, and I still prefer it for simple (short) things (see my example), but as soon as things get more complex, sed sucks.
I just gave you a general answer for your comment ;-)

anyway, hope we can focus on Talmash's problem now ..
0
 
LVL 3

Expert Comment

by:mrn060900
ID: 6358718
To change the text in a file you could use:

find . -type f -print | xargs file | grep -i text | cut -f1 -d: | while read

  file; do

vi $file >/dev/null 2>&1 <<!

:%s,Linux,GNU/Linux,g

:wq

!

done

Regards Mike
www.unixonline.co.uk
0
 
LVL 6

Author Comment

by:Talmash
ID: 6555292
do I have something else to say but thank you very much .

Tal , moshav nechalim
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 130
Pressing cancel button with C# UI Automation 3 66
WinWaitActive parameters 12 31
countEvens challenge 2 98
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question