The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 07:24 AM
Search and Replace in Ksh DeepakXavier Shell Programming and Scripting 9 05-28-2007 05:11 AM
sed search and replace d__browne UNIX for Dummies Questions & Answers 7 04-26-2006 06:46 AM
Search and replace sed or tr bridgeje Shell Programming and Scripting 6 10-28-2003 04:54 AM
search and Replace mukeshannamalai UNIX for Advanced & Expert Users 4 09-14-2001 03:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8  
Old 04-17-2007
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
No. You didn't specify it in your request.
Quote:
To list all files in your directory and sub-directories, replace
`ls -1` by `find .`
Danny,
I dont think we may require `ls -1` in the for loop in case we are listing the files/directories in the Current working directory just an * will do.

Also note `find .` or `ls -1` or simple * will list all files & directories,so we may to have use,

Quote:
for file in $(find . -name '*' -type f -print ) ; do
#Replacement Logic
done
Please correct me if am wrong.

Thanks
Nagarajan Ganesan
Reply With Quote
Forum Sponsor
  #9  
Old 04-17-2007
Registered User
 

Join Date: Feb 2007
Posts: 20
So I guess this would be the final solution ?

for file in $(find . -name '*' -type f -print ) ; do
sed 's/mysite.com/mysite.net/g' $FileName > $$TempFile
mv $$TempFile $FileName
done

If i want to run this command do I type this out on the command line or do i have to make a shell script and run the shell script ?
Reply With Quote
  #10  
Old 04-17-2007
Shell_Life's Avatar
Registered User
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Thank you ennstate,
You are right, the "find ." will list everything, including the directories.
Also, there is no need for "-name '*'" nor "-print".
The "find . -type -f" is sufficient to list all regular files and not directories.
Thanks.
Reply With Quote
  #11  
Old 04-17-2007
Registered User
 

Join Date: Feb 2007
Posts: 20
Hi,

Do I run this on the command line or do I have to run this command in a script ?
Reply With Quote
  #12  
Old 04-17-2007
Shell_Life's Avatar
Registered User
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
dannyd,
The best way to run this is:
1) Create a file with the above commands.
2) Change its permissions to executable (ie 755, etc.).
3) Type the file name in the command line.
Reply With Quote
  #13  
Old 04-17-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
no need the for loop
Code:
find . -size +1024c -type f -name "*.txt" -print0 | xargs -0 sed -i 's/term/replace/g'
NB. -i option only for gnu sed.
Reply With Quote
  #14  
Old 04-17-2007
Registered User
 

Join Date: Feb 2007
Posts: 20
Quote:
Originally Posted by ghostdog74
no need the for loop
Code:
find . -size +1024c -type f -name "*.txt" -print0 | xargs -0 sed -i 's/term/replace/g'
NB. -i option only for gnu sed.
I can run this on the command line, but...

Wouldnt this search only files that end with .txt and would it search subfolders ?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0