sed search and replace recursively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed search and replace recursively
# 1  
Old 09-02-2009
Bug sed search and replace recursively

Hi,

I tried making a shell script which recursively search in a given directory for all files *.txt and then search and replace some text and after that
save each file as $filename.dynamips.txt

I would like to get this done with sed. I tried but couldn't get it to work.
BTW this is not homework. It is just a bunch of lab files I want to convert for using with dynamips

Thanks!

s/interface GigabitEthernet0\/2//g + delete next following line
s/spanning-tree mode pvst/\!/g
s/spanning-tree extend system-id/\!/g
s/vlan internal allocation policy ascending/\!/g
s/ip http server/no ip http server/g
s/ip http secure-server/no ip http secure-server/g
s/version 12/\!/g
s/call rsvp-sync/\!/g
s/mgcp/\!/g
s/gatekeeper/\!/g
s/memory-size 15/\!/g
s/scheduler allocate/\!/g
s/warm-reboot/\!/g
s/Serial0\/0\/0/Serial0\/0/g
s/Serial0\/0\/0/Serial0\/0/g
s/Serial0\/1\/0/Serial0\/1/g
s/Serial0\/2\/0/Serial2\/0/g
s/Serial0\/2\/1/Serial2\/1/g
s/Ethernet0\/0/FastEthernet0\/0/g
s/interface GigabitEthernet0\/1/FastEthernet1\/0/g
# 2  
Old 09-02-2009

What are you having trouble with?

If the sed script works with one file, it will work with all of them.

Write a script that works on a single file and call it with:

Code:
find . -type f -name '*.txt' -exec your_script {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search/Replace in multiple files recursively

Hi there, I am using AIX and trying to search and replace a string with another string in multiple files in different directories. I wanted to search replace in steps so I don't change all of the instance anywhere in the server at once, minimizing impact. STEP 1: -------- I first searched... (5 Replies)
Discussion started by: zaino22
5 Replies

2. Shell Programming and Scripting

sed -s does not search recursively

I would like to export the 5th line from every file within a directory. I am using GNU sed because we have no Unix or Linux environment. I used the following statement: sed -s -n 5p c:\directory\*.* but I only get the 5th line from one of the files in the directory. I am desperate for a... (1 Reply)
Discussion started by: hollingv
1 Replies

3. Shell Programming and Scripting

Need help with search and replace using SED

Hi guys, thanks for accepting me in your forum .. I am trying to clean some hacked PHP files using SSH .. I am using this command: find . -type f -print0 | xargs -0 sed -i '/god_mod/d' <?php ... (3 Replies)
Discussion started by: wisam74us
3 Replies

4. UNIX for Dummies Questions & Answers

search and replace with sed

Hi All I have a simple text file and I want to be able to replace any alpha character and comma combination with any other symbol of my choice here is the text file I want to replace: pear apple ban,ana grape ",g1234," te,st1 here is how it should look afterwards: pear... (4 Replies)
Discussion started by: greg_b
4 Replies

5. Shell Programming and Scripting

Sed - search and replace help.

Hi everyone, basically I am been cleaning data by using simple sed commands So what i have below has been working for me. sed 's/="//g' trade.csv > tradeb.csv sed 's/"//g' tradeb.csv > trade2.csv but now i don't want to remove all the quotes just the ones if i encounter this ... (1 Reply)
Discussion started by: raz0r
1 Replies

6. UNIX for Dummies Questions & Answers

How to use 'sed' to search and replace?

Hello - I have a very large file in which a certain numbers are repeated. I find that using vi to edit the entire file is useless. How should i use sed to find a replace such as this text: To replace: 145.D25.D558 With: 215.22.45.DW I tried this command: sed... (4 Replies)
Discussion started by: DallasT
4 Replies

7. Shell Programming and Scripting

sed search and replace

hi, im new for sed, anyone can help me to these in sed command my output file.txt "aaa",a1,bbb "ddd",a1,ccc "eee",a1,www need to change a1, to "a1"," output i need "aaa","a1","bbb "ddd","a1","ccc "eee","a1","www thanks in advance fsp (2 Replies)
Discussion started by: fspalero
2 Replies

8. Shell Programming and Scripting

find and replace a search string recursively in files

Hi , I have a directory structure as dir and subdirectories and files under it and so on.now I need to find the files which contain the search string under every dir and subdir and replace . my search string is like searchstring=/a/b string to be replaced=/a/c/b please help. ... (7 Replies)
Discussion started by: mohanpadamata
7 Replies

9. UNIX for Dummies Questions & Answers

Search/Replace with Sed

Is there a way to use the sed command to 1) search a specified pattern 2) in the line where that pattern is found, replace from character N to character N+4 with a new 4-character string. Thks in advance! (5 Replies)
Discussion started by: mvalonso
5 Replies

10. UNIX for Dummies Questions & Answers

sed search and replace

Hello Folks, Anyone know how I can replace this line in file.xml <oacore_nprocs oa_var="s_oacore_nprocs">8</oacore_nprocs> with this line <oacore_nprocs oa_var="s_oacore_nprocs">1</oacore_nprocs> using sed or awk ? Thanks for your time. Cheers, Dave (7 Replies)
Discussion started by: d__browne
7 Replies
Login or Register to Ask a Question