[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

script to replace files names and text

Posted on 2001-07-18
9
Medium Priority
?
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

649 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