Solved

script to replace files names and text

Posted on 2001-07-18
9
162 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
no14 challenge 14 70
Window placement 17 85
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 336
mapAB Challlenge 35 155
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‚Ķ
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

792 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