Deleting string from file of same name within several directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting string from file of same name within several directories
# 1  
Old 02-24-2005
Question Deleting string from file of same name within several directories

I searched the forum, but I don't think I was able to find exactly what I'm looking for.

Is there a command in shell where I can delete a particular string from every file it occurs in (where the file is named the same, but sits in different directories)?

Example: Within the directory I am in, there are 30+ directories with different names, each beginning with 2004 and then the rest of a date. Within each of those directories, there is a directory named "small" and within that directory is a file named "slideshow.shtml" (ie 2004*/small/slideshow.shtml)

I want to delete the string " <!--#include file="photo_main_site.html"--> " from every slideshow.shtml file without having to navigate into each directory and pulling up the file with an editor.

Is that possible?
I am a newbie, please type slowly. Smilie
And thanks in advance!!!

Nicole
# 2  
Old 02-24-2005
not tested.....
Code:
#!/bin/ksh

find . -type f -name 'slideshow.shtml' | while read file
do
    ex - "${file}" <<EOF
s/ <!--#include file="photo_main_site.html"--> //g
wq!
EOF
done

# 3  
Old 02-24-2005
Quote:
Originally Posted by vgersh99
not tested.....
Code:
#!/bin/ksh

    ex - "${file}" <<EOF
s/ <!--#include file="photo_main_site.html"--> //g

Vgersh can we use this way

ex - "${file}" | s/ <!--#include file="photo_main_site.html"--> //g
# 4  
Old 02-24-2005
Quote:
Originally Posted by thumsup9
Vgersh can we use this way

ex - "${file}" | s/ <!--#include file="photo_main_site.html"--> //g
no, but you can do it like this as well - a bit terser:
Code:
(echo 's/ <!--#include file="photo_main_site.html"--> //g'; echo 'wq!') | ex -s "${file}"

# 5  
Old 02-24-2005
Not sure what to do

Am I just supposed to type those lines into the shell prompt as you put them? (the first reply)

Sorry to ask such a dumb question, but if I put the first line in and hit enter, I get a > and then if I put the rest of the lines in and then hit enter, it pauses, then gives me the prompt back. Then when I check one of the files, the string is still there. I must be doing something wrong. Smilie

Nicole
# 6  
Old 02-24-2005
Quote:
Originally Posted by halo969
Am I just supposed to type those lines into the shell prompt as you put them? (the first reply)

Sorry to ask such a dumb question, but if I put the first line in and hit enter, I get a > and then if I put the rest of the lines in and then hit enter, it pauses, then gives me the prompt back. Then when I check one of the files, the string is still there. I must be doing something wrong. Smilie

Nicole
Nicole:

At the prompt type
$ vi myscript.ksh
paste the code here (paste by right click on ur mouse)
now do ESC + SHIFT :
enter wq!
$ . myscript.ksh

BTW thanks vgersh.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to Search a FILE for a STRING in multiple DIRECTORIES

Hi, Can someone please help me with a Command to Search a FILE for a STRING in multiple DIRECTORIES. I am searching for the VIP in HTTPD.CONF in multiple httpd instances. I am using find ./ -name "httpd.conf" | xargs grep 10.22.0.141 cut -d: -f3- | cut -d ' ' -f4 | sort | uniq -c ... (1 Reply)
Discussion started by: crosairs
1 Replies

2. Shell Programming and Scripting

Issue deleting all lines (having a specific string) in a file

I'm trying to create a script. There are 2 files - fileA.log & fileB.log fileA.log has the below data : aaaa cccc eeee fileB.log has the below data : cjahdskjah aaaa xyz jhaskjdhas bbbb abc ajdhjkh cccc abc cjahdskjah ... (7 Replies)
Discussion started by: Pandee
7 Replies

3. Shell Programming and Scripting

Script for deleting files and directories when the file system reaches the threshold

Hi Can someone assist in writing a script. I have a filesystem named /sybase in my aix lpar. When this filesystem becomes 94% full all the files and directories under /sybase/logs should be deleted immediately. :confused: (7 Replies)
Discussion started by: newtoaixos
7 Replies

4. Shell Programming and Scripting

Deleting all files recursively from directories while ignoring one file type

Hi, Seems like I need help again with a problem: I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders except for .mp3 and .MP3 files. I tried it with globalignoring mp3 files, finding and deleting all other files, which resulted in all files... (3 Replies)
Discussion started by: pasc
3 Replies

5. Shell Programming and Scripting

Deleting directories

I want to delete directories which are empty and directories which are 2 level deep. example: /app/data/logs/G07696115/G07696115 So if a same directory is there inside G07696115 with the same name G07696115, i want to find and delete that alone(Make sure you do not touch directory any... (4 Replies)
Discussion started by: gtm004
4 Replies

6. UNIX for Dummies Questions & Answers

Deleting lines that contain a specific string from a space delimited text file?

Hi, I have a space delimited text file that looks like the following: 250 rs10000056 0.04 0.0888 4 189321617 250 rs10000062 0.05 0.0435 4 5254744 250 rs10000064 0.02 0.2403 4 127809621 250 rs10000068 0.01 NA 250 rs1000007 0.00 0.9531 2 237752054 250 rs10000081 0.03 0.1400 4 17348363... (5 Replies)
Discussion started by: evelibertine
5 Replies

7. Shell Programming and Scripting

deleting files in sub directories!

Hello out there, I want to setup a crontab feature to remove temporary pdf files from sub directories that are older than 30 days. I want to presevere the directory structer though. I got this far for a command. Will this remove the pdf's in subdirectories or just directly under the pdf folder? If... (6 Replies)
Discussion started by: vsekvsek
6 Replies

8. Shell Programming and Scripting

Deleting string within a file that finishes with .log

Hello, This is my first post. Nice forum! I have a file trls.results small exemple of content (actually the file can be very big): ./security/htaccess.htm ./security/ipcount.log ./adhoc/sql/datamod06.sql So there is 3 paths to 3 different files... I want to remove every string that has a... (9 Replies)
Discussion started by: Jacob106106
9 Replies

9. Shell Programming and Scripting

Deleting a line from a file based on one specific string instance?

Hello! I need to delete one line in a file which matches one very precise instance of a string only. When searching the forum I unfortunately only found a solution which would delete each line on which a particular string occurs. Let's assume I have a file composed of thousands of lines... (4 Replies)
Discussion started by: Black Sun
4 Replies

10. UNIX for Dummies Questions & Answers

deleting all the sub directories

hello., i am creating a certain sub directories as apart of my requirement, and then later on i have to delete all those sub directories.. ____________________________________________________ DIR1="/home/pavi/cvs/20071426/TEMP" echo " DIR1 is : " $DESTDIR1 echo... (2 Replies)
Discussion started by: pavan_test
2 Replies
Login or Register to Ask a Question