Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Scripting..(?) Batch find/replacer
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
dleifelohcs
Apprentice
Apprentice


Joined: 10 Jul 2003
Posts: 160
Location: UNH

PostPosted: Mon Feb 23, 2004 3:43 pm    Post subject: Scripting..(?) Batch find/replacer Reply with quote

I have, say, 500 files that all have this one line in them.

This line needs to be replaced with a different line. What can I do to find/make a sort of batch, multi-file replacer? (Each file is different, but they all have this one line in them, only once)

I know this isn't Gentoo specific, but I didn't know where else to look!

Thanks
Back to top
View user's profile Send private message
tomk
Bodhisattva
Bodhisattva


Joined: 23 Sep 2003
Posts: 7221
Location: Sat in front of my computer

PostPosted: Mon Feb 23, 2004 4:15 pm    Post subject: Reply with quote

Use rename:

Code:
rename oldline newline *

_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
ecatmur
Advocate
Advocate


Joined: 20 Oct 2003
Posts: 3595
Location: Edinburgh

PostPosted: Tue Feb 24, 2004 6:17 am    Post subject: Reply with quote

Use sed -i or perl -p -i -e.
Back to top
View user's profile Send private message
charlieg
Advocate
Advocate


Joined: 30 Jul 2002
Posts: 2149
Location: Manchester UK

PostPosted: Tue Feb 24, 2004 9:23 am    Post subject: Reply with quote

tomk wrote:
Use rename:

Code:
rename oldline newline *


I thought that only worked on file names? (Hence the name 'rename'...)
_________________
Want Free games?
Free Gamer - open source games list & commentary

Open source web-enabled rich UI platform: Vexi
Back to top
View user's profile Send private message
neilhwatson
l33t
l33t


Joined: 06 Feb 2003
Posts: 719
Location: Canada

PostPosted: Tue Feb 24, 2004 2:45 pm    Post subject: Reply with quote

Code:

find <path> -name file.* -exec perl  -pi -e 's/old/new/gi' {} \;

_________________
The true guru is a teacher.
Neil Watson
Back to top
View user's profile Send private message
tomk
Bodhisattva
Bodhisattva


Joined: 23 Sep 2003
Posts: 7221
Location: Sat in front of my computer

PostPosted: Wed Feb 25, 2004 1:48 pm    Post subject: Reply with quote

charlieg wrote:
I thought that only worked on file names? (Hence the name 'rename'...)


Whoops I must have totally misread the question. :oops:
_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum