To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.off-topic.geekOpen lugnet.off-topic.geek in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Off-Topic / Geek / 4103
4102  |  4104
Subject: 
Re: TXT-file question
Newsgroups: 
lugnet.off-topic.geek
Date: 
Wed, 18 Dec 2002 20:44:15 GMT
Viewed: 
467 times
  
Dave Schuler wrote:
Hello all:
   I have a bunch of text files, each of which contains a character sequence
(say, ABCD) that I need to change (say, to WXYZ).  The character sequence is
within the body of each file, rather than the title.  Is there an easy
method of swapping out the ABCD's for the WXYZ's without manually opening
each file and doing a find/replace?

  Thanks once again to all my geek-savvy friends!

     Dave!

Are you on windows? (if so I don't know) or on UNIX/linux?

If you're on UNIX or linus you could use sed.

Somethign like: (this is untested so YMMV)

for FILE in *.txt; do
   if sed 's/ABCD/WXYZ/g' < $FILE >$FILE.new; then
     mv $FILE.new $FILE
   else
     echo Pattern not found or other error in $FILE.
     rm $FILE.new
   fi
done

If you hav Cygnus installed on your windows machine that might
work also.

-Kyle



--
                                    _
-------------------------------ooO( )Ooo-------------------------------
Kyle J. McDonald                 (o o)         Systems Support Engineer
Sun Microsystems Inc.            |||||
Enterprise Server Products                        Kyle.McDonald@Sun.COM
1 Network Drive BUR03-4630       \\\//          voice:   (781) 442-2184
Burlington, MA 01803             (o o)            fax:   (781) 442-1542
-------------------------------ooO(_)Ooo-------------------------------



Message has 1 Reply:
  Re: TXT-file question
 
(...) or, if you have perl (windows or unix), you can do this: perl -i.bak -p -e 's/ABCS/WXYZ/g' *.txt which will create a backup (file.txt.bak) before changing all 'ABCD' to 'WXYZ'. :) Dan (22 years ago, 18-Dec-02, to lugnet.off-topic.geek)

Message is in Reply To:
  TXT-file question
 
Hello all: I have a bunch of text files, each of which contains a character sequence (say, ABCD) that I need to change (say, to WXYZ). The character sequence is within the body of each file, rather than the title. Is there an easy method of swapping (...) (22 years ago, 18-Dec-02, to lugnet.off-topic.geek)

13 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR