Solved

script to replace files names and text

Posted on 2001-07-18
9
163 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Decoding 32 bit binary streams 6 54
repeatSeparator  java  challenge 13 58
fizzArray  challenge 1 109
Window placement 17 95
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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